elyngved / ruby-mws

A Ruby library that wraps the Amazon MWS API.
MIT License
41 stars 64 forks source link

Just updated and am seeing errors #15

Open rlad opened 10 years ago

rlad commented 10 years ago

Hello, I was using a previous version of this gem and it was working fine, but I just updated and now I am having problems:

def get_response # takes a block as a parameter
    #amazon requests may be throttled, so we need to check before returning results
    throttled = true
  s = 5
    while throttled == true 
        the_response = yield                                                
        if the_response.has_key?("error_response")                                  # all error responses should have this key
            if the_response.error_response.error.has_key?("code")                   
                if the_response.error_response.error.code == "RequestThrottled"
                    sleep(s.seconds)                                            # throttle times may vary, so retry after 10 sec
          s = s*1.5
                end
            else
                puts "unknown error"
                return nil 
            end
        else
            throttled = false
            return the_response
        end
    end
end

Now, I don't even see the throttled response and instead I get a program crash as follows:

-> "<?xml version=\"1.0\"?>\n<ErrorResponse xmlns=\"https://mws.amazonservices.c
om/Orders/2011-01-01\">\n  <Error>\n    <Type></Type>\n    <Code>RequestThrottle
d</Code>\n    <Message>Request is throttled</Message>\n  </Error>\n  <RequestID>
740e1669-dab8-4776-b8dd-ebf1938c958a</RequestID>\n</ErrorResponse>\n"
read 291 bytes
Conn close
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/response.rb:24
:in `handle_error_response': RequestThrottled: Request is throttled (MWS::ErrorR
esponse)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/r
esponse.rb:10:in `parse'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/b
ase.rb:45:in `send_request'
        from (eval):4:in `list_order_items'
        from mws.rb:98:in `block (2 levels) in <main>'
        from mws.rb:29:in `get_response'
        from mws.rb:98:in `block in <main>'
        from mws.rb:87:in `each'
        from mws.rb:87:in `<main>'

Also:

Thanks very much.