-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Error handling for JSON::ParseException not working if request with invalid JSON body #852
Comments
I put |
Yeah, I'm thinking as long as HttpMethodOverrideHandler is before the RouterHandler, it should be ok to move it. We'll probably need to test a few things, but good catch! |
…#854) Because part of this handler looks at the request body, it can fail if the json is malformed. I believe this is totally acceptable behavior. The reason I point this out is because in lucky-cli, this handler is put before the ErrorHandler ([reference](https://github.com/luckyframework/lucky_cli/blob/master/src/web_app_skeleton/src/app_server.cr.ecr\#L5-L15)) when it probably shouldn't be. This is most likely the cause of #852
Sorry to chime in late. I think HttpMethodOverrideHandler should be before ErrorHandler because we need to make sure the http method is correct. I think what we should do is rescue json parse exceptions in the method override handler or something. Bit busy right now, but will try to tackle this later |
and thank you for reporting this @ucibar and for investigating the cause. That was extremely helpful! |
Closed by ed1e51b |
Hi, I'm using
crystal 0.29.0
andlucky 0.15.1
.If I send a
POST
request with invalid JSON body, lucky response with500
. But there is a handler method forJSON::ParseException
in theactions/errors/show.cr
file andlucky
not trigger the method. And if I delete the handler forJSON::ParseException
, It must trigger default handler for unhandled exceptions but It isn't trigger any handler.Example:
Let's say we have a action named
Bug::Create
:lucky gen.action.api Bug::Create
And we have error handler for
JSON::ParseException
:And we send a
POST
request with invalid JSON, e.g.{"foo"="bar"}
and we got500
andUnhandled exception on HTTP::Handler: Unexpected char '=' at 2:12 (JSON::ParseException)
.But if you doing
JSON.Parse
operations in your actions/forms/models and if there is a invalid JSON,JSON::ParseException
perfectly captured by error handler method. For example:And
JSON::ParseException
will be captured by error handler.Sorry for bad English and language mistakes.
The text was updated successfully, but these errors were encountered: