Skip to content

Commit

Permalink
rack/middleware: default to 500 instead of 0 if code can't be found
Browse files Browse the repository at this point in the history
When `ActionDispatch::ExceptionWrapper` fails to return a code for an exception,
then it returns 0. This confuses our backend, so we should convert that into 500
as the most reasonable default value.
  • Loading branch information
kyrylo committed Nov 20, 2018
1 parent dc37c8c commit 41277bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -73,3 +73,6 @@ Naming/UncommunicativeMethodParamName:
Style/SymbolArray:
Exclude:
- gemfiles/*.gemfile

Style/NumericPredicate:
Enabled: false
2 changes: 2 additions & 0 deletions lib/airbrake/rack/middleware.rb
Expand Up @@ -147,6 +147,8 @@ def find_status_code(payload)
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(
payload[:exception].first
)
status = 500 if status == 0

return status
end

Expand Down
17 changes: 17 additions & 0 deletions spec/integration/rails/rails_spec.rb
Expand Up @@ -311,5 +311,22 @@
wait_for(a_request(:put, routes_endpoint).with(body: body)).
to have_been_made.once
end

it "defaults to 500 when status code for exception returns 0" do
expect(Airbrake[:default]).to receive(:notify_request).and_call_original
allow(ActionDispatch::ExceptionWrapper).
to receive(:status_code_for_exception).and_return(0)

head '/crash'
sleep 2

wait_for_a_request_with_body(/"errors"/)

body = %r|
{"routes":\[{"method":"HEAD","route":"\/crash\(\.:format\)","status_code":500
|x
wait_for(a_request(:put, routes_endpoint).with(body: body)).
to have_been_made.once
end
end
end

0 comments on commit 41277bc

Please sign in to comment.