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 handling support for "problem details" rfc7807 #26507

Closed
dirweis opened this issue Feb 4, 2021 · 11 comments
Closed

Exception handling support for "problem details" rfc7807 #26507

dirweis opened this issue Feb 4, 2021 · 11 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement

Comments

@dirweis
Copy link

dirweis commented Feb 4, 2021

According to RFC-7807 (see https://tools.ietf.org/html/rfc7807) it would be useful to provide an invalid-params field in case of 400 Bad Request errors. This field is supposed to contain ALL violated parameters, no matter which Exception type is caught by the ExceptionHandler annotated methods.

Since in case of multiple violations it is possible that Exceptions of different types occur (e.g. ConstraintViolationException and MethodArgumentTypeMismatchException from one request), those Exception objects must be available in the ExceptionHandler.

A solution would be a resolver for a List of Exceptions.

@bclozel bclozel transferred this issue from spring-projects/spring-boot Feb 4, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 4, 2021
@bclozel
Copy link
Member

bclozel commented Feb 4, 2021

We could use this issue as the basis for a broader rfc7808 "Problem Details for HTTP APIs". Spring Boot has an issue about this (see spring-projects/spring-boot#19525), but we're likely to need infrastructure support from Spring Web Frameworks.

@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 4, 2021
@bclozel bclozel added this to the General Backlog milestone Feb 4, 2021
@bclozel bclozel changed the title Spring Boot Exception Handler get all Exceptions at once Exception handling support for "problem details" rfc7807 Feb 4, 2021
@dirweis
Copy link
Author

dirweis commented Feb 4, 2021

Great, thank you, @bclozel !
Maybe you can use my second Issue in Exception Handlers as well as the basis for a broader rfc7808 "Problem Details for HTTP APIs":
https://github.com/spring-projects/spring-boot/issues/25105

@npathai
Copy link

npathai commented Feb 28, 2021

I can work on this if it's available. I am a first time contributor, do let me know if this is something a first timer can take a dig on.

@bclozel bclozel added the status: pending-design-work Needs design work before any code can be developed label Mar 1, 2021
@bclozel
Copy link
Member

bclozel commented Mar 1, 2021

Hello @npathai

I've tagged this issue with "status: pending-design-work".

In this case, we know that Spring HATEOAS and 3rd party Spring Boot starters provide features in this space. We don't know how this would be support in Spring Framework yet. From turning business exceptions into problem details instances, providing an error handling infrastructure, helping to localize error messages and URLs to error pages, etc. Some of this could be in Spring Framework, other parts should belong in Spring Boot.

We know that this feature requires significant changes and we'd like to tackle it in the Spring Framework 6.x timeline.

We're happy to have community members like you willing to help. In general, you should try and look for "status: ideal-for-contribution" issues. Arguably, they're not really common in Spring Framework because many issues are really specific, but other Spring projects have more of those. Many community members start by contributing documentation improvements, fixing typos, or answering questions on StackOverflow.

Thanks!

@npathai
Copy link

npathai commented Mar 2, 2021

@bclozel Sure, sounds reasonable. Thanks for the insight. I contribute in other projects but was starting to look into open issues in Spring. I will look into other Spring projects 👍

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 11, 2021

@dirweis there is only a single exception that is raised and resolved through the HandlerExceptionResolver contract. So it would be ConstraintViolationException or MethodArgumentTypeMismatchException, never both. Can you clarify what you have in mind?

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on and removed status: pending-design-work Needs design work before any code can be developed labels Jun 11, 2021
@rstoyanchev rstoyanchev removed this from the General Backlog milestone Jun 11, 2021
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jun 18, 2021
@bclozel bclozel removed status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue labels Jun 18, 2021
@dirweis
Copy link
Author

dirweis commented Jun 18, 2021

@rstoyanchev What can I explain deeper hereby? What is not clear? I'm aware that only a ConstraintViolationException or MethodArgumentTypeMismatchException or any other type of exception can be caught in an Exception Handler at once, never both or 3 or n for n>1 at the same time. And I would really appreciate if that would be possible, no matter what Exception type.
I can imagine this poor fella had something similar in mind:
https://stackoverflow.com/questions/4221064/spring-exceptionhandler-handling-multiple-kinds-of-exceptions

Have an ice weekend, Dirk

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 21, 2021

@dirweis when the issue was originally accepted, the intent was to support for RFC 7807. We now have an official umbrella issue #27052 and I'm looking at the specifics of your request.

You seem to be asking for some variant of the HandlerExceptionResolver that can handle multiple exceptions at the same time. That doesn't make sense because as soon as there is an exception it bubbles up and we look for a HandlerExceptionResolver to resolve it. In other words we will never have more than one exception to handle at once.

The StackOverflow question you referenced on the other hand is about how to handle different exceptions types in the same way, not at the same time.

In terms of the RFC 7807 invalid-params, I haven't looked very closely but I imagine that when we translate ConstraintViolation errors from a JSR-303 validator into a BindException, all the validation issues could be listed in invalid-params. So this could be a fit for exceptions that list multiple problems, even if I can't think of any other (built-in) exceptions that fit that description.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Jun 21, 2021
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jun 28, 2021
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants