Custom Grails Exception Handling

Following the example with custom exception handling in Grails, I came to the following code:

exceptionHandler.exceptionMappings = [
    'my.project.AccessDeniedException': '/accessDenied',
    'my.project.NoSessionException' : '/accessDenied',
    'java.lang.Exception': '/errorProduction'
]

This works fine for the first two types of exceptions, but all other exceptions, such as GroovyPagesException , are no longer handled by Grails, they are handled by the servlet container.

How can I handle all exceptions with Grails (1.3)?

+3
source share
2 answers

It works:

UrlMappings.groovy:

"500"(controller: 'errors', action: 'handle')

And the controller:

class ErrorsController {

    def handle = {
        def exception = request.exception.cause.class
        if(exception == my.project.NoSessionException ||
               exception == my.project.AccessDeniedException)
            render(view: '/accessDenied')
        else
            render(view: '/errorProduction')
    }

}
+7
source

500 ? UrlMappings .

  "500"(controller: "error", action: "cartGone", exception: CartGoneException)    

, ?

+1

Source: https://habr.com/ru/post/1788217/


All Articles