lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
MIT License
307 stars 130 forks source link

More expressive errors #54

Closed hakanensari closed 8 years ago

hakanensari commented 8 years ago

Current errors are not expressive:

client.get_feed_submission_result id
# => Excon::Errors::NotFound: Expected(200) <=> Actual(404 Not Found)

If you don't already have a notion of what this means, the workaround is to rescue and peek into response:

begin
  client.get_feed_submission_result id
rescue Exception => ex
  puts ex.response.parse
  # => {"Type"=>"Sender", "Code"=>"FeedProcessingResultNotReady", "Message"=>"Feed Submission Result is not ready for Feed 191837016796", "Detail"=>nil}
end

Instead, we could perhaps throw an error that inherits from Excon::Errors::NotFound, sets class name to the value of CodeFeedProcessingResultNotReady in this case—and set the error message to the value of Message. Inheriting from the original error should make this largely backwards-compatible, assuming people rescue Excon error types to handle specific cases (throttling, etc.).