Sha256: 2116a978db2b00b26cdfbc3baeb7057e80070f04b04ea49dde1a31f677b9860b

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

module Faraday
  class Response::FullContactErrors < Response::Middleware
    def on_complete(env)
      case env[:status]
        when 400
          raise FullContact::BadRequest.new(error_message(env), env[:response_headers])
        when 401
          raise FullContact::Unauthorized.new(error_message(env), env[:response_headers])
        when 403
          raise FullContact::Forbidden.new(error_message(env), env[:response_headers])
        when 404
          raise FullContact::NotFound.new(error_message(env), env[:response_headers])
        when 422
          raise FullContact::Invalid.new(error_message(env), env[:response_headers])
        when 429
          # Note: not currently in use
          raise FullContact::RateLimited.new(error_message(env), env[:response_headers])
        when 500
          raise FullContact::InternalServerError.new(error_message(env), env[:response_headers])
        when 502
          raise FullContact::BadGateway.new(error_message(env), env[:response_headers])
        when 503
          raise FullContact::ServiceUnavailable.new(error_message(env), env[:response_headers])
      end
    end

    def error_message(env)
      "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
    end

    def initialize(app)
      super
      @parser = nil
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
fullcontact-api-ruby-0.1.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.18.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.17.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.16.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.15.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.14.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.13.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.12.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.11.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.10.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.9.0 lib/faraday/response/fullcontact_errors.rb
fullcontact-0.8.2 lib/faraday/response/fullcontact_errors.rb