lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
https://lineofflight.github.io/peddler/
MIT License
307 stars 130 forks source link

InvalidMarketplace error from Amazon turns into a parse error #145

Closed marytal closed 4 years ago

marytal commented 4 years ago

Hey! I'm attempting to submit an inventory update feed, but the account I'm submitting it for is suspended. Instead of getting Peddler::Errors::InvalidMarketplace, I see ArgumentError · wrong number of arguments (given 2, expected 0..1)

I cannot rescue Peddler::Errors::InvalidMarketplace (even though I've defined the error in my repo) because I'm thinking the parsing error happens before it gets translated.

# frozen_string_literal: true
module Peddler
  module Errors
    class InvalidMarketplace < StandardError; end
  end
end

Feed Response (through ScratchPad)

<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
<Error>
  <Type>Sender</Type>
  <Code>InvalidMarketplace</Code>
  <Message>Feed rejected</Message>
  <Detail/>
</Error>
<RequestID>[REDACTED]</RequestID>
</ErrorResponse>

Steps to reproduce:

Thanks for your help (and this gem)!

hakanensari commented 4 years ago

What line is throwing that error—could you paste here the traceback?

marytal commented 4 years ago

Sorry, here it is:

vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/errors/builder.rb:34:in `initialize': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/errors/builder.rb:34:in `new'
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/errors/builder.rb:34:in `build'
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/errors/builder.rb:20:in `call'
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/client.rb:152:in `handle_http_status_error'
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/client.rb:121:in `rescue in run'
    from vendor/bundle/ruby/2.6.0/gems/peddler-2.3.0/lib/peddler/client.rb:113:in `run'
hakanensari commented 4 years ago
# frozen_string_literal: true
module Peddler
  module Errors
    class InvalidMarketplace < StandardError; end
  end
end

It's a "type error." You need to inherit from Peddler::Errors::Error, not StandardError. I added a guard to alert about this in runtime, which should make things more resilient.

marytal commented 4 years ago

Thank you!!