Repository navigation
Allow rescue from parse errors - #34341
Conversation
aa16aba to
1158fce
Compare
There was a problem hiding this comment.
assert_response :ok
Could we make an assertion on the body's content to ensure that the response came from rescuing the exception
82ceb6d to
2795339
Compare
There was a problem hiding this comment.
Should not the response be "parser error"?
There was a problem hiding this comment.
Whoops, I'll fix that, and look into why its failing.
There was a problem hiding this comment.
I didn't realize this at first, but it only blows up if you reference params in the controller. Is that acceptable or should we look at rescuing on the request.filtered_parameters call in instrumentation's #process_action?
There was a problem hiding this comment.
That is the expected behavior for me.
2795339 to
20a2a11
Compare
rafaelfranca
left a comment
There was a problem hiding this comment.
This looks good to me. I'll ask other people to review too to check if I'm not missing something before merging.
cc @JoshCheek
|
Oh, super exciting! I'll try it out this morning and report back with my results. |
|
👍 This worked for me!! Ty ty ❤️ I was able to remove my I think it would be worth changing the example in the docs to show that you can access the original exception by receiving the parse error and asking for its rescue_from ActionDispatch::Http::Parameters::ParseError do |exception|
render status: 400, json: { errors: [ exception.cause.message ] }
end |
|
Any further comments on this @jeremy or @pixeltrix? |
There was a problem hiding this comment.
Maybe clarify the behaviour here with a comment explaining that it will rescue all exceptions - it's not a construct that you see every day.
Otherwise 👍
[Gannon McGibbon + Josh Cheek]
20a2a11 to
6b3faf8
Compare
|
Ty! 🎉 |
|
Hmm, this is on master, but not released in 5.2.2 Looking at the git tag, the released branch diverged from master on 30 Jan (explanatory comments are in pink comments at the end of each line) The long-running separate branches seem like they're part of some intentional process like git-flow or something like that. But I read RELEASING_RAILS.md and skimmed the contribution guide and don't see an explanation, so figured I'd mention it in case it slipped through the cracks. |
Use rescue_from block instead of the CatchJsonParseErrors middleware See rails/rails#34341
Use rescue_from block instead of the CatchJsonParseErrors middleware See rails/rails#34341


Related to #34287, allows parameter parse errors to be caught by
rescue_fromblocks.Closes #34287.
r? @rafaelfranca