-
Notifications
You must be signed in to change notification settings - Fork 38.5k
DomainClassConverter causes 500 if an entity could not be found #32052
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
Comments
@Floppy012 |
The mentioned behavior is caused by Edit: It's caused by this line Line 143 in 899de4f
|
Thanks for the report. The conversion mechanism in spring-core is pretty low level, and I don't think it's in a good position to make decisions about what exceptions mean. In this case a converter with a higher level concern that should also be handled externally. It would make more sense to have an You can also handle |
That would still mean I have to override the DCC to implement a null check and throw an exception. In that case, it should be documented somewhere. It still feels like a workaround just to have spring no longer return a
I haven't tried that yet, but would I also be able to find out why the exception was triggered? If it comes from the DCC returning |
True, yes.
|
@Floppy012 Spring will send 400 instead of 500 since 6.0.14, see #31382. |
Thanks for the information. |
The way the DomainClassConverter acts is unclear to me. The documentation states that it can be used to have
@PathParameter
directly being looked up instead of manually doing it.So the following code inside of a controller works perfectly:
However, when I provide an
entityId
that does not exist, spring responds with 500 stating that theentityId
parameter has not been provided. Which is not true, it has been provided the DCC could not find an entity to that value. So the correct response should be a 404.I came across this issue #26296 where two solutions were provided and additionally added to the documentation:
PathVariable
settingrequired=false
entityId
is not present in the request.MissingPathVariableException
to return a 404As of what I've found out, there is no way to trigger a 404 without using any of the two above solutions. The expected behavior that I imagine (for the above code) would look like this:
GET /
400 Bad Request
GET /not-existing
404 Not Found
GET /existing
200 OK
get(Entity)
Additionally for optional path variables (i.e.
@PathVariable(required = false)
):GET /
200 OK
get(null)
GET /not-existing
404 Not Found
GET /existing
200 OK
get(Entity)
Since changing the behavior would probably be considered a breaking change one less breaking solution could be to allow the DCC to throw certain exceptions that would then not get interpreted as conversion failures and simply passed through (so users can override the DCC to throw
EntityNotFoundException
instead of it returningnull
)The text was updated successfully, but these errors were encountered: