-
-
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
adding option to allow grape to handle Grape::Exception when rescue all is set #1398
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,43 @@ def app | |
end | ||
end | ||
|
||
context 'api with rescue_from :grape_exceptions handler' do | ||
subject { Class.new(Grape::API) } | ||
before do | ||
subject.rescue_from :all do |_e| | ||
rack_response 'message was processed', 400 | ||
end | ||
subject.rescue_from :grape_exceptions | ||
|
||
subject.params do | ||
requires :beer | ||
end | ||
subject.post '/beer' do | ||
'beer received' | ||
end | ||
end | ||
|
||
def app | ||
subject | ||
end | ||
|
||
context 'with content_type json' do | ||
it 'returns body parsing error message' do | ||
post '/beer', 'test', 'CONTENT_TYPE' => 'application/json' | ||
expect(last_response.status).to eq 400 | ||
expect(last_response.body).to include 'message body does not match declared format' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the full body here? Maybe we can make an exact match? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The full body is
Kind of a pain to match the full thing. Totally could do. Was following the precedent set on the tests below: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine, thanks. |
||
end | ||
end | ||
|
||
context 'with content_type xml' do | ||
it 'returns body parsing error message' do | ||
post '/beer', 'test', 'CONTENT_TYPE' => 'application/xml' | ||
expect(last_response.status).to eq 400 | ||
expect(last_response.body).to include 'message body does not match declared format' | ||
end | ||
end | ||
end | ||
|
||
context 'api without a rescue handler' do | ||
subject { Class.new(Grape::API) } | ||
before do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this back please.