Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

Scott Wheeler commented on Upcoming change in API limit calculations

$
0
0

Here's a slightly updated version of our snippet -- I realized looking again at the old one that it'd eat non-429 connection errors rather than rethrowing them.  This fixes that:

module ActiveResource
  class Connection
    def request_with_sleeper(*args, &block)
      if self === ShopifyAPI::Base.connection
        if ShopifyAPI::Base.connection.response && ShopifyAPI.credit_maxed?
          sleep(0.5)
        end
        begin
          request_without_sleeper(*args, &block)
        rescue ActiveResource::ConnectionError => ex
          if ex.response.code.to_s == '429'
            sleep(0.5)
            retry 
          else
            raise ex
          end
        end
      else
        request_without_sleeper(*args, &block)
      end
    end

    alias_method_chain :request, :sleeper
  end
end

 


Viewing all articles
Browse latest Browse all 25503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>