Skip to content

Allow using functional WebMvc ServerRequest/ServerResponse based exception handler as central exception handler #36633

@hajdamak

Description

@hajdamak

Currently it is possible to create "controller" style exception handler using @ControllerAdvice and @ExceptionHandler annotations and then make it central exception handler for application and also make it handle security exceptions with:

authenticationEntryPoint = AuthenticationEntryPoint { request, response, exception ->
    handlerExceptionResolver.resolveException(request, response, null, exception)
}

accessDeniedHandler = AccessDeniedHandler { request, response, exception ->
     handlerExceptionResolver.resolveException(request, response, null, exception)
}

However if you create "router" style exception handler (in WebMvc functional router with onError), it won't handle security exceptions with above configuration, nor will it handle resource not found exceptions from dispatcher servlet.
"controller" style exception handler will handle correctly all of these.

It is unfortunate that application that is solely router based is forced to have one style of exception handlers for it's routers and other style for security and "general" exceptions.
It should be possible to make router style exception handlers handle these general exceptions.

Meanwhile is there anyway to achieve this with some workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions