Sha256: ce8195348f7da38adcd1aed010cc328ffa9f7c2fe38dd323197fc13f74779420

Contents?: true

Size: 584 Bytes

Versions: 7

Compression:

Stored size: 584 Bytes

Contents

require "redd/error"

module Redd
  module Response
    # Raises the appropriate error when one comes up.
    class RaiseError < Faraday::Middleware
      # Call the middleware.
      # @param faraday
      def call(faraday)
        @app.call(faraday).on_complete do |env|
          if error = Redd::Error.from_response(env)
            if error == Redd::Error::RateLimited
              time = env.body[:json][:ratelimit]
              fail error.new(env, time)
            else
              fail error.new(env)
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redd-0.4.3 lib/redd/response/raise_error.rb
redd-0.4.2 lib/redd/response/raise_error.rb
redd-0.4.1 lib/redd/response/raise_error.rb
redd-0.4.0 lib/redd/response/raise_error.rb
redd-0.3.0 lib/redd/response/raise_error.rb
redd-0.2.0 lib/redd/response/raise_error.rb
redd-0.1.6 lib/redd/response/raise_error.rb