lineofflight / peddler

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

400 Bad Request Errors #103

Closed ayb closed 6 years ago

ayb commented 6 years ago

Getting the following 400 error from Excon while processing:

Excon::Error::BadRequest: Expected(200) <=> Actual(400 Bad Request)

    from /home/rails/shared/bundle/ruby/2.3.0/gems/excon-0.59.0/lib/excon/middlewares/expects.rb:7:in `response_call'
    from /home/rails/shared/bundle/ruby/2.3.0/gems/excon-0.59.0/lib/excon/middlewares/response_parser.rb:9:in `response_call'
    from /home/rails/shared/bundle/ruby/2.3.0/gems/excon-0.59.0/lib/excon/connection.rb:389:in `response'
    from /home/rails/shared/bundle/ruby/2.3.0/gems/excon-0.59.0/lib/excon/connection.rb:253:in `request'
    from (eval):6:in `post'
    from /home/rails/shared/bundle/ruby/2.3.0/gems/peddler-1.6.5/lib/peddler/client.rb:167:in `run'
    from /home/rails/shared/bundle/ruby/2.3.0/gems/peddler-1.6.5/lib/mws/orders/client.rb:47:in `list_orders'

Strange things about this:

I have a strange feeling this is related to the end time - I was using 2.minutes.ago in ISO8601 date format, but I think I fixed this on my end by just removing it since that's the MWS API default value anyway. (I've been using this gem for years and have never had this issue before so does not quite make sense.)

hakanensari commented 6 years ago

Hard to figure out if you have not been able to reproduce this even in console.

I don't know if it's feasible, but you may want to switch to using a new set of error classes I have that I do not enable by default. You can see here how to do so. Their output should be more descriptive than the Excon 400.

ayb commented 6 years ago

This has happened to me a few times over the past couple of years and I've always thought it was a throttling issue until I realized that throttling would be a 503 code (vs 400).

I think the issue is the server timestamp on my end, guessing my server time is slowly slipping and/or somehow ended up so that 2.minutes.ago on production was < 2 minutes ago on Amazon's server and caused the 400.

Removing that param definitely is helping.

Thanks for the tip on the errors - I will work on that on my end.

I'm going to close this out as I don't think it is related to Peddler or Excon.