Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ebay_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class << self
end
end

response(404) do |_, _, (data, *)|
data = data.to_h
error = data.dig("errors", 0) || {}
code = error["errorId"]
message = error["longMessage"] || error["message"]
raise NotFound.new(code: code), message
end

# https://go.developer.ebay.com/api-call-limits
response(429) do |_, _, (data, *)|
data = data.to_h
Expand Down
3 changes: 3 additions & 0 deletions lib/ebay_api/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def initialize(*args, code: nil, data: nil, **)
class InvalidAccessToken < Error; end
class AlreadyExists < Error; end

# HTTP 404 from eBay.
class NotFound < Error; end

# HTTP 500 from eBay. May be retried in most cases.
class InternalServerError < Error; end

Expand Down
13 changes: 13 additions & 0 deletions spec/error_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ class EbayAPI
end
end
end

context "when offer already deleted" do
let(:response) do
open_fixture_file "resource_not_found"
end

it do
expect { subject }.to raise_error(EbayAPI::NotFound) do |ex|
expect(ex.code).to eq 25713
expect(ex.message).to match /This Offer is not available/
end
end
end
end
5 changes: 5 additions & 0 deletions spec/fixtures/resource_not_found
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTTP/1.1 404 Not Found
Content-Length: 188
Content-Type: application/json

{"errors":[{"errorId":25713,"domain":"API_INVENTORY","subdomain":"Selling","category":"REQUEST","message":"This Offer is not available.","parameters":[{"name":"text1","value":"123456"}]}]}