How to send error messages between Grails controllers?

I am trying to send an error message from the grails controller to the Grails error controller in order to display the error message in the HTTP response, but I'm not sure which parameter contains the error message in the error controller.

URLMappings.groovy

All 500 errors are displayed in 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 ErrorsController so that I can output it in an HTTP response.

+5
source share
2 answers

, -. :

def myAction = {
    try {
        ...
    } catch (Exception e) {
        flash.message = e.message
        response.sendError(500)
    }
}

, ? , grails "500". request.exception.

+8

ErrorsController:

def serverError() {
    render request.getAttribute('javax.servlet.error.message')
}

e.getMessage().

0

All Articles