I have the next scenario in my UrlMappings.groovy:
"/user/$action?" (controller:"user")
"/admin/$action?" (controller:"user")
"500"(controller:"error", action:"show")
"404"(controller:"error", action:"show")
And I need to know on the errorController from which controller was thrown the exception (if any) that raises the error 500, and show diferent error pages for users and admin.
Any ideas?
Thanks in advance.
You can access the exception in your ErrorController via request.exception
. The top level exception always points to the controller where it was thrown so you can find out the controller name with exception.className
. Here's a very simple example.
class ErrorController {
def show = {
def exception = request.exception
render(text: "Exception in ${exception?.className}",
contentType: "text/plain", encoding: "UTF-8")
}
}