-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Errors caused by invalid body content are not processed by rescue handlers #904
Comments
Ok, I wrote a small spec and found out that the issue is related to the content type definition that is sent by the user. When specifying |
It's definitely a problem, would love it to see this fixed. |
… error that translates into a customized bad request response (+spec)
… error that translates into a customized bad request response (+spec)
… error that translates into a customized bad request response (+spec)
I updated the pull-request #906 and added a possible solution how to handle the parsing errors. It shows that I catch the error and raise a new |
… error that translates into a customized bad request response (+spec)
… error that translates into a customized bad request response (+spec)
… error that translates into a customized bad request response (+spec)
… error that translates into a customized bad request response (+spec) Conflicts: CHANGELOG.md lib/grape.rb lib/grape/locale/en.yml
… error that translates into a customized bad request response (+spec)
Fixed in #906 |
Hi all,
I ran into a more or less severe issue today. I am running grape directly behind rack (NO rails) and found an issue that has also been described in issue #389, which however was run behind rails.
Here is the problem:
If I fire a request against my API with the body set to an random non-JSON value, for instance simply
test
, theMultiJson
parser returns anMultiJson::ParserError
error with the message795: unexpected token at 'test'
that occurs in the Grape::Middleware::Formatter and is then thrown as400
response message.What I would expect is that my
rescue_all
handler gets notified of the error and can handle the situation. Instead, Grape::Middleware::Error.call catches the thrown error, which then gets processed in the Grape::ErrorFormatter::Base.In there, two lines (actual comments) perfectly explain the next issue:
Ok, so there the call crashes again and raises a
NoMethodError
. This error then finally gets processed by my rescue_all handler. Nevertheless I receive a response with the status500
instead of the actual expected400
.Even if the exception in the Grape::ErrorFormatter::Base would be prevented, the call would not reach the rescue handlers.
In my opinion the rescue handlers should get a chance to handle the error since it is directly related to the request body.
If a have some spare time I'll try to write a spec for the issue in the next couple of days.
The text was updated successfully, but these errors were encountered: