- 
        Couldn't load subscription status. 
- Fork 38.8k
Description
I am customizing HandlerFunction:
For web MVC:
public class ServletHandlerFunction implements HandlerFunction<ServerResponse> {
    @Override
    public ServerResponse handle(ServerRequest request) throws Exception {
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet!");
    }
}For web Flux:
public class ReactiveHandlerFunction implements HandlerFunction<ServerResponse> {
    @Override
    public Mono<ServerResponse> handle(ServerRequest request) {
        return Mono.error(new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet!"));
    }
}I expect that the ResponseStatusException should be handled by ResponseEntityExceptionHandler (when setting spring.{mvc,webflux}.problemdetails.enabled to true), but the result is that the exception in ReactiveHandlerFunction can be handled, while the one in ServletHandlerFunction cannot. The reason is found here (org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#shouldApplyTo), where exceptions thrown from HandlerFunction are not processed.
This is somewhat frustrating, especially when developing frameworks. I hope that both webmvc and webflux can have the same behavior for exception handling. It would be really helpful if ExceptionHandlerExceptionResolver could handle ResponseStatusException thrown by HandlerFunction.