Generic URLMapping in Grails for all 4xx or 5xx Errors

705 Views Asked by At

I am using Grails 2.4.4 and would like to define a generic UrlMapping for a range of HTTP-error-codes (like 450-499, 510-540).

I've found some related questions - even on SO - but the answers are either outdated or not working.

The container does not start once I use regular expressions on error-mappings.

For instance, this simple example will fail:

"$errorCode" {
     controller = "error"
     action = "general"
     constraints {
          errorCode(matches:/\d{3}/)
     }
}

Does anyone know how I may approach this?

1

There are 1 best solutions below

0
Anshul On

I tried doing same using Filters but we cannot redirect again after checking status code in httpResponse hence that also doesn't help.

As per grails-doc "Mapping to Response Codes"

http://grails.github.io/grails-doc/3.1.x/guide/single.html#urlmappings

we can only hard code them and redirect it to mentioned controller and action. So you need to mention all http codes and handle all of them separately.

Thanks.