I'm trying to pass an error message from a grails controller to a grails error controller in order to display an error message in the HTTP response, but I'm not sure what parameter is holding the error message in the error controller.
URLMappings.groovy
All 500 errors are mapped to ErrorsController
"500"(controller: "errors", action: "serverError")
GenericController
def {
try{
//do some work
}catch(Exception e){
response.sendError(500, e.getMessage())
}
}
ErrorsController
def serverError = {
render( how can I access the exception details here?? )
}
I need to access the exception in the ErrorsController so I can output it to the HTTP response.
The usual way to pass short informational messages between controllers is to place it in the flash scope. For example:
def myAction = {
try {
...
} catch (Exception e) {
flash.message = e.message
response.sendError(500)
}
}
In this particular case, though, why are you catching the exception? If you let the exception fall through, grails will automatically generate a server error and call the "500" mapping. In your error controller, the exception will be available as request.exception
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With