Class: Faraday::Response::RaiseError

Inherits:
Middleware show all
Defined in:
lib/faraday/response/raise_error.rb

Constant Summary collapse

ClientErrorStatuses =
400...600

Instance Method Summary collapse

Methods inherited from Middleware

#call

Methods inherited from Middleware

dependency, inherited, #initialize, loaded?, new

Methods included from MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware

Constructor Details

This class inherits a constructor from Faraday::Middleware

Instance Method Details

#on_complete(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/faraday/response/raise_error.rb', line 5

def on_complete(env)
  case env[:status]
  when 404
    raise Faraday::Error::ResourceNotFound, response_values(env)
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
  when ClientErrorStatuses
    raise Faraday::Error::ClientError, response_values(env)
  end
end

#response_values(env) ⇒ Object



17
18
19
# File 'lib/faraday/response/raise_error.rb', line 17

def response_values(env)
  {:status => env.status, :headers => env.response_headers, :body => env.body}
end