Sha256: 0d5bbfbce5bf4d6b8e9f30ad3d78cf7ef12d5b80b528d743b4e2a542e90ba5f7

Contents?: true

Size: 863 Bytes

Versions: 14

Compression:

Stored size: 863 Bytes

Contents

require 'faraday'

# @private
module Faraday
  # @private
  class Response::RaiseHttp5xx < Response::Middleware
    def on_complete(env)
      case env[:status].to_i
      when 500
        raise FullContact::InternalServerError.new(error_message(env, "Internal server error."), env[:response_headers])
      when 502
        raise FullContact::BadGateway.new(error_message(env, "FullContact is down or being upgraded."), env[:response_headers])
      when 503
        raise FullContact::ServiceUnavailable.new(error_message(env, "Service unavailable."), env[:response_headers])
      end
    end

    private

    def error_message(env, body=nil)
      "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.fullcontact.cc/ for updates on the status of the FullContact service."
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
fullcontact-0.7.0 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.6.1 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.6.0 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.5.0 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.4.4 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.4.1 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.3.3 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.3.2 lib/faraday/response/raise_http_5xx.rb
fullcontacter-0.3.2 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.3.1 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.3.0 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.2.0 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.1.4 lib/faraday/response/raise_http_5xx.rb
fullcontact-0.1.3 lib/faraday/response/raise_http_5xx.rb