Sha256: 207dc81d02da97a68c4c1a0bcb69f923e3e38a0bc2c56ab611db5fdf230acacc

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 KB

Contents

module AppnexusApi
  module Faraday
    module Response
      class RaiseHttpError < ::Faraday::Response::Middleware
        def on_complete(response)
          case response[:status].to_i
          when 400
            raise AppnexusApi::BadRequest, error_message(response)
          when 401
            raise AppnexusApi::Unauthorized, error_message(response)
          when 403
            raise AppnexusApi::Forbidden, error_message(response)
          when 404
            raise AppnexusApi::NotFound, error_message(response)
          when 406
            raise AppnexusApi::NotAcceptable, error_message(response)
          when 422
            raise AppnexusApi::UnprocessableEntity, error_message(response)
          when 500
            raise AppnexusApi::InternalServerError, error_message(response)
          when 501
            raise AppnexusApi::NotImplemented, error_message(response)
          when 502
            raise AppnexusApi::BadGateway, error_message(response)
          when 503
            raise AppnexusApi::ServiceUnavailable, error_message(response)
          end
        end

        def error_message(response)
          msg = "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}"
          if errors = response[:body] && response[:body]["errors"]
            msg << "\n"
            msg << errors.join("\n")
          end
          msg
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
appnexusapi-1.0.0 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.1.3 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.1.2 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.1.1 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.1.0 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.9 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.8 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.7 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.6 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.5 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.4 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.3 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.2 lib/appnexusapi/faraday/raise_http_error.rb
appnexusapi-0.0.1 lib/appnexusapi/faraday/raise_http_error.rb