Sha256: 7e003bb5a28dd1ef95d113e496c7e0df2550b4b2353e65c962f40d3a187603eb

Contents?: true

Size: 762 Bytes

Versions: 33

Compression:

Stored size: 762 Bytes

Contents

require 'faraday/middleware'
require 'zendesk_api/error'

module ZendeskAPI
  module Middleware
    # @private
    module Request
      # Faraday middleware to handle HTTP Status 429 (rate limiting) / 503 (maintenance)
      # @private
      class RaiseRateLimited < Faraday::Middleware
        ERROR_CODES = [429, 503].freeze

        def initialize(app, options = {})
          super(app)
          @logger = options[:logger]
        end

        def call(env)
          response = @app.call(env)

          if ERROR_CODES.include?(response.env[:status])
            @logger&.warn 'You have been rate limited. Raising error...'
            raise Error::RateLimited, env
          else
            response
          end
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
zendesk_api-3.1.1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.1.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.5 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.4 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.2 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-3.0.0.rc1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-2.0.1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-2.0.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.38.0.rc2 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.38.0.rc1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.37.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.36.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.35.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.34.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
discourse_zendesk_api-1.0.1 lib/zendesk_api/middleware/request/raise_rate_limited.rb
discourse_zendesk_api-1.0.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.33.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb
zendesk_api-1.32.0 lib/zendesk_api/middleware/request/raise_rate_limited.rb