spring-projects / spring-projects/spring-framework
Allow using functional WebMvc ServerRequest/ServerResponse based exception handler as central exception handler
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how WebMvc functional router onError handlers are invoked, then compare that path with @ControllerAdvice/@ExceptionHandler handling through HandlerExceptionResolver. Check the integration points for AuthenticationEntryPoint, AccessDeniedHandler, and dispatcher-servlet resource-not-found errors; done means router-style handlers can receive these general exceptions consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100