Skip to content

Commit

Permalink
Handle 413 responses (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
stympy authored Oct 3, 2023
1 parent 5a32e16 commit 19f2b5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ adheres to [Semantic Versioning](http://semver.org/).
### Added
- Support for Karafka (#480)
- Support for nested `to_honeybadger_context` (#488)
- Explain 413 responses from API (#492)

### Fixed
- `Honeybadger::Config#respond_to?` would always return true (#490)
Expand Down
3 changes: 2 additions & 1 deletion lib/honeybadger/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Response
429 => "Your project is currently sending too many errors.\nThis issue should resolve itself once error traffic is reduced.".freeze,
503 => "Your project is currently sending too many errors.\nThis issue should resolve itself once error traffic is reduced.".freeze,
402 => "The project owner's billing information has expired (or the trial has ended).\nPlease check your payment details or email support@honeybadger.io for help.".freeze,
403 => "The API key is invalid. Please check your API key and try again.".freeze
403 => "The API key is invalid. Please check your API key and try again.".freeze,
413 => "The payload is too large.".freeze
}.freeze

# Initializes the Response instance.
Expand Down
2 changes: 2 additions & 0 deletions lib/honeybadger/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def handle_response(msg, response)
when 403
warn { sprintf('Error report failed: API key is invalid. id=%s code=%s', msg.id, response.code) }
suspend(3600)
when 413
warn { sprintf('Error report failed: Payload is too large. id=%s code=%s', msg.id, response.code) }
when 201
if throttle = dec_throttle
info { sprintf('Success ⚡ https://app.honeybadger.io/notice/%s id=%s code=%s throttle=%s interval=%s', msg.id, msg.id, response.code, throttle, throttle_interval) }
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/honeybadger/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ def handle_response
end
end

context "when 413" do
let(:response) { Honeybadger::Backend::Response.new(413, %({"error":"Payload exceeds maximum size"})) }

it "warns the logger" do
expect(config.logger).to receive(:warn).with(/too large/)
handle_response
end
end

context "when 201" do
let(:response) { Honeybadger::Backend::Response.new(201) }

Expand Down

0 comments on commit 19f2b5c

Please sign in to comment.