lineofflight / peddler

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

Add InvalidRequestException to list of known error codes. #135

Closed andrewhavens closed 5 years ago

andrewhavens commented 5 years ago

I think the Amazon documentation might be outdated since it is missing InvalidRequestException from its list of known error codes. I have seen this error in cases like this:

<ErrorResponse xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
  <Error>
    <Type>Sender</Type>
    <Code>InvalidRequestException</Code>
    <Message>Value justatest for parameter Address.PostalCode is invalid. Reason: InvalidValue.</Message>
  </Error>
  <RequestId>ff6fee03-1bc1-455b-80ed-19e441b0f133</RequestId>
</ErrorResponse>

Since error classes are dynamically created, the constant that was being defined was Peddler::Errors::InvalidRequestException. However, I couldn't figure out why I couldn't rescue from that type of error and getting undefined constant errors. Turns out it was missing from this list.

hakanensari commented 5 years ago

Hi Andrew

There are actually quite a few error types they do not explicitly document on the page I use as reference. I originally decided not to include any for the sake of consistency and future maintenance.

If you need to rescue InvalidRequestException in your code, you could explicitly define it when initialising your app.

require 'peddler/errors/error'

module Peddle
  module Errors
    InvalidRequestException = Class.new(Error)
  end
end

Thanks for taking the time to submit the PR.