Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Handler methods do not receive the original exception as argument [SPR-15701] #20258

Closed
spring-issuemaster opened this issue Jun 24, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jun 24, 2017

Doron Gold opened SPR-15701 and commented

In WebFlux, methods annotated with @ExceptionHandler (either in Controllers or in a class annotated with @ControllerAdvice) should be able to receive the thrown exception as an argument.
However, if the exception has a cause, only the cause exception is passed to InvocableHandlerMethod#invoke.
In case the exception handler method declares as parameter a specific exception type, when that exception is thrown (assuming it has a non-null cause) the exception handler fails to invoke with the following error:

java.lang.IllegalStateException: No suitable resolver for argument 0 of type 'org.springframework.issues.errorhandling.CustomException' on public java.lang.String org.springframework.issues.errorhandling.HelloController.handleCustomException(org.springframework.issues.errorhandling.CustomException)

How to Reproduce

See the attached link to a reproduction project

Controller code from that project:

@RestController
public class HelloController {

    public static final String ERROR_MSG = "An error occurred!";

    @RequestMapping("/hello")
    public String hello() {
        final NestedException nested = new NestedException("nested");
        throw new CustomException("outer", nested);
    }

    @ExceptionHandler()
    public String handleCustomException(final CustomException e) {
        return ERROR_MSG;
    }
}

Invoke the error handler by sending the following HTTP request: http://localhost:8080/hello

Notice that in web-mvc the exact same code works fine.
This can be confirmed by changing the following gradle dependency:
compile("org.springframework.boot:spring-boot-starter-webflux")
to: compile("org.springframework.boot:spring-boot-starter-web")


Affects: 5.0 RC2

Reference URL: spring-projects/spring-framework-issues#158

Referenced from: commits a6d616d

3 votes, 2 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.