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

Support @ResponseStatus-annotated exceptions on WebFlux [SPR-16567] #21109

Closed
spring-projects-issues opened this issue Mar 8, 2018 · 6 comments
Closed
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 8, 2018

Andreas Schilling opened SPR-16567 and commented

As of now using @ResponseStatus annotations on custom exceptions or exception handler methods of @ControllerAdvice classes is not supported.
This is a pitfall when coming from the classic web stack where this is kind of the idiomatic way to apply specific response codes to custom exceptions.

Either using ResponseStatusException directly or applying a wrapper (e.g. through a @ControllerAdvice) is a workaround but feels like it is something the framework should do.
As described in this comment this seems easily doable through the ResponseStatusExceptionHandler.

A small test setup is attached to this ticket. Running ./gradlew test currently fails as the response status for the custom exception is not set to 400 but by default to 500.


Affects: 5.0.4

Attachments:

Issue Links:

  • #21097 Using @ControllerAdvice with WebFlux

Referenced from: commits ba5ef64, b8d94f8

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 8, 2018

Rossen Stoyanchev commented

Just to be clear, we're talking about support for built-in handling of @ResponseStatus-annotated exceptions, in the same way that ResponseStatusException is already handled, correct? Keep in mind that is unrelated to @ControllerAdvice which is for explicit handling of exceptions by the application.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 8, 2018

Andreas Schilling commented

Ah yes, sorry for the confusion. I meant the built-in variant using annotated exceptions. That's also the variant I included in the sample.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 8, 2018

Rossen Stoyanchev commented

Got it, yes. Just double checking.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 11, 2018

Jose Carlos commented

We are on webflux 5.0.6 and we are experiencing the same issue.

Custom exception annotated with @ResponseStatus(whatever) Returns a 500. The only difference we can think of is the fact that we are using Kotlin.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 11, 2018

Jose Carlos commented

Using @ControllerAdvice + @ResponseStatus on the other hand works. Decorated annotations do not.

Not sure if the ExceptionHandler for annotated exceptions is disabled in WebFlux of if it is actually a bug.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 11, 2018

Rossen Stoyanchev commented

This was an improvement, so saying "the same issue" doesn't make sense and doesn't help. Also the change for this ticket has been released and the ticket is permanently closed.

You will need to create a new ticket with a fresh description based on behavior relative to 5.0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants