How to map Http error codes in a grails plugin's URLMapping.groovy

837 views Asked by At

In our application we are mapping a set of HTTP error codes to an error controller which produces a json message with the corresponding http error code as the response status. The relevant portion of URLMappings.groovy is pretty simple:

        "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")

Now, I'm trying to take the ErrorController.groovy class and the url mappings above out of the application and make that a plugin so that we can the same error handling in other applications.

In my plugin called "error-controller",I've created an ErrorControllerUrlMappings.groovy class and have moved the above mappings into here. In this UrlMappings.groovy, it seems I can define any mapping I want just fine, eg "/foo", "/bar", etc... but I cannot the get the HTTP error code mappings to register.

When I trigger one of these error codes from the application where the plugin is installed, I get the default tomcat message for that error code. The ErrorController in the plugin is never hit.

Interestingly though, 500 errors are being handled by the controller in the plugin.

Is it possible to create URL mappings for these http error codes in my plugin's ErrorControllerUrlMappings.groovy?

  • Thanks
0

There are 0 answers