How to globally handle HTTP errors in Grails (status codes 4xx / 5xx)?

Is there a way in Grails to catch all the possible HTTP errors before they are sent to the client browser in order to be able to handle the content sent to the client? I mean all HTTP status codes 4xx and 5xx , and not only 403, 404 and 500, like others.

What I would like to do is to catch all HTTP errors in the first place without specifying them one by one, and then in the second step I will filter (for example, in the error controller) the specific error codes that I would like to process (for example, 400 ), but at least those that I would not indicate would display the general error pattern that I defined.

If this cannot be done (or should not be), what HTTP error codes should really be checked and processed? I can at least see that these codes occur at some point: 400, 401, 403, 404, 405, 500, 501, 503. And also, how to handle them using HTTP response code mappings?

Thanks!

+6
error-handling grails
source share
1 answer

didn't really try, but maybe a number limit might work?

"$errorCode" { controller = "errors" action = "displayError" constraints { errorCode(matches:/\d{3}/) } } 
+2
source

All Articles