Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails redirect to a page in case of error

Here is a simple question. Is there any possibility of, if in any case there's an error in an application and the server show us an error page, instead redirect everything to a default page ?

Covering all errors.. is that possible ?

like image 317
VictorArgentin Avatar asked May 31 '11 18:05

VictorArgentin


1 Answers

Grails already does this for you. If an exception bubbles up to the container, it gets handled as an HTTP 500 (Internal Server Error). With conf/URLMappings.groovy you can control what happens what happens when error statuses occur.

Here's the default mapping for 500 responses (from conf/URLMappings.groovy):

"500"(view:'/error')

This tells the application to render the error view, which is located in views/error.gsp. If you want to change this, you can. You could redirect to a controller/action if you want:

// will go to 'custom' action of ErrorController, which you would create yourself
"500"(controller: "error", action: "custom")

You can configure this for any HTTP response status. See the URL Mappings documentation. If you need finer control over different exceptions that might be encountered, look at the "Declarative Error Handling" section in the referenced docs above.

like image 91
Rob Hruska Avatar answered Oct 09 '22 01:10

Rob Hruska