zalando / problem-spring-web

A library for handling Problems in Spring Web MVC
MIT License
1.03k stars 125 forks source link

Simplest way to add the type information to every Problem? #561

Closed JayChandler closed 3 years ago

JayChandler commented 3 years ago

It seems only on certain exceptions the type field will be set for instance ConstraintViolationException. It would be nice if there would be an easy way to create this informtion for every exception without the need of overwriting everything.

whiskeysierra commented 3 years ago

"type" (string) - A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be "about:blank".

https://tools.ietf.org/html/rfc7807#page-5

So the type is optional and there is no easy or obvious way dynamically generate something.

What would be your expectation?

JayChandler commented 3 years ago

"type" (string) - A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be "about:blank". https://tools.ietf.org/html/rfc7807#page-5

So the type is optional and there is no easy or obvious way dynamically generate something.

What would be your expectation?

For the constraint violation you have somehting like

public static final String TYPE_VALUE = "https://zalando.github.io/problem/constraint-violation"

Why not just use something like

"https://zalando.github.io/problem/" + throwable.getClass().getSimpleName() or provide a callback where an URI can be returned for a provblem?

whiskeysierra commented 3 years ago

Why not just use something like

"https://zalando.github.io/problem/" + throwable.getClass().getSimpleName()

I don't really see how that would add any value. The type should give you some additional information, on top of the status itself. Not only wouldn't that be the case, we would instead even leaking internals of the exception to problem/status mapping. As an example, multiple different exceptions map to 400 Bad Request right now, but clients shouldn't need to deal with same translated java exception names in the type.

whiskeysierra commented 3 years ago

provide a callback where an URI can be returned for a provblem?

That one might actually be useful.

no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.