在我们的应用程序中,我们将一组HTTP错误代码映射到错误控制器,该错误控制器生成一个json消息,其中相应的http错误代码作为响应状态。 URLMappings.groovy的相关部分非常简单:
"501"(controller: "error", action: "index")
"500"(controller: "error", action: "index")
"422"(controller: "error", action: "index")
"415"(controller: "error", action: "index")
"406"(controller: "error", action: "index")
"405"(controller: "error", action: "index")
"404"(controller: "error", action: "index")
"403"(controller: "error", action: "index")
"401"(controller: "error", action: "index")
"400"(controller: "error", action: "index")
现在,我试图将ErrorController.groovy类和上面的url映射从应用程序中取出并制作一个插件,以便我们可以在其他应用程序中进行相同的错误处理。
在我的插件名为" error-controller"中,我创建了一个ErrorControllerUrlMappings.groovy类,并将上述映射移到了这里。在这个UrlMappings.groovy中,似乎我可以定义任何我想要的映射,例如" / foo"," / bar"等...但是我无法获取HTTP要注册的错误代码映射。
当我从安装插件的应用程序中触发其中一个错误代码时,我会获得该错误代码的默认tomcat消息。插件中的ErrorController永远不会被命中。
有趣的是,插件中的控制器正在处理500个错误。
是否可以在我的插件的ErrorControllerUrlMappings.groovy中为这些http错误代码创建URL映射?