Sha256: 6961fc360a8184ef1ead642546451fb6ed065f57f21dc16d27dd99276ce6e761

Contents?: true

Size: 479 Bytes

Versions: 3

Compression:

Stored size: 479 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|
          error = Redd::Error.from_response(env)
          if error
            info = Redd::Error.parse_error(env[:body])
            fail error, info
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redd-0.1.2 lib/redd/response/raise_error.rb
redd-0.1.1 lib/redd/response/raise_error.rb
redd-0.1.0 lib/redd/response/raise_error.rb