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

Panic Should Generate a 500 Status Code #78

Closed
mt35-rs opened this issue Nov 30, 2022 · 2 comments
Closed

Panic Should Generate a 500 Status Code #78

mt35-rs opened this issue Nov 30, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@mt35-rs
Copy link
Contributor

mt35-rs commented Nov 30, 2022

When lines like this are triggered, they don't return a 500 Internal Server Error (and ideally an RFC 7807 problem report). Instead, I would expect the handler to recover and return a 500 error along with an RFC 7807 description of the problem.

I should add that it is very easy to trigger such panics as a result of various validation steps. It doesn't seem reasonable to the client to simply terminate the request without any kind of response (which is what happens now).

@danielgtaylor danielgtaylor added the bug Something isn't working label Dec 5, 2022
@mtiller
Copy link
Contributor

mtiller commented Jan 10, 2023

Just to revisit this, are there really OpenAPI specs that declare 500 responses? It seems like a 500 response almost always arises as a result of a bug/flaw/unforeseen issue. My point is, it seems like a 5XX error should trigger a validation failure. I can definitely see it for 4XX because this is indicative of the client doing something wrong and, therefore, we not only need the client to know they failed but obviously enumerate (via the OpenAPI spec) all the ways the client can fail in this request. But I just don't see this with a 5XX. I think those should not trigger validation failures. My 2 cents.

@danielgtaylor
Copy link
Owner

This behavior has changed a bit in v2. There is no longer a restriction on what status codes you can set and the panic handling is now router-specific, so you can choose to use your router's panic handler, Huma v1's panic handler, or do something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants