I sometimes annotate my controllers with a description that I'd like to show in the error message:
// ControllerType is a custom annotation
@ControllerType(description= "this does foo bar")
class MainController {
...
With that in place, and based on the post from Aoi Karasu, here's how to extract information from the initial Controller:
class ErrorsController {
def index() {
def initialController = request.exception?.className
if (initialController) {
def controller = grailsApplication.getArtefact("Controller", initialController).getReferenceInstance()
render "Controller: ${initialController}, annotations ${controller.getClass().getDeclaredAnnotations()}"
return
}
render 'no initial controller'
}
}
request.exception?.className combined with grailsApplication.getArtefact allows to retrieve the controller, from which you can, for example, extract annotations