Grails is already doing this for you. If a bubble occurs in the container, it is treated as HTTP 500 (Internal Server Error). Using conf/URLMappings.groovy you can control what happens when an error condition occurs.
This uses the default mapping for 500 responses (from conf/URLMappings.groovy ):
"500"(view:'/error')
This tells the application to display the error view, which is located in views/error.gsp . If you want to change this, you can. You can redirect to 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. See URL Mappings Documentation. If you need finer control over the various exceptions that may occur, see the “Declarative Error Handling” section in the above documents.
source share