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
Introduce Rack::BadRequest
exception.
#1996
Comments
We already have |
I've given an example of where I want to use it initially. I don't feel strongly about introducing it in other areas, but I suppose we could (I'm sure there are other areas which are a bad request). Do you expect servers to rescue |
I guess one concern could be someone wanting to control the response (status code, body) when We have gotten similar feedback in Puma, that users want control over the "lowlevel error" response (puma/puma#2341). |
Someone can always add a middleware to intercept the error and handle it. It really depends on whether we want the multipart issue to default to a 500 error (unhandled exception) or have some standard way of the server knowing it was actually a bad request. |
Makes sense to me letting the server know that it was a bad request. |
Currently, A generic 400 error by the server is probably not what most people want, though I can understand it being an improvement on the existing 500 error. For browser-based apps, you'd probably want a nicer error page (created by the framework in use). For JSON-based APIs, you would probably want the body to be in JSON format. One backwards compatible possibility is a |
I agree, the web framework should catch and deal with errors. I agree, using a module can be a preferable approach with few backwards compatibility issues. I actually don't really mind what we do, as long as it improves the current situation. |
Okay, in summary, in Rack 3.1, there will exist We could consider backporting this to 3.0 but I don't have a strong opinion about it. |
I'm against backporting this. We should only backport bug fixes, not features, and only if there is not significant compatibility breakage (or the bug fix is a security fix). |
I'm fine with that. |
Something like:
This class would be used to indicate failures within Rack, and servers should be able to catch it and correctly map it to a failed response.
There are places in the multipart parsing code and
Rack::Request
where various conditions can be the result of a bad client HTTP request. It feels like it would be useful to have an exception that indicates that. The current situation right now, is we may raise anIOError
or some other exception which becomes a 500 Internal Server Error, which while correct in a way (the server basically blew up), doesn't really reflect the nature of the "request being invalid" - e.g. a bad request, preconditions failed, etc.See #1994 (comment) for an example use case.
The text was updated successfully, but these errors were encountered: