Class: Faraday::RaiseErrors

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/faraday/raise_errors.rb,
lib/faraday/raise_errors/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/faraday/raise_errors.rb', line 8

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 400..599
    error = Faraday::HTTP::ERRORS.fetch(env[:status], :UnrecognizedResponse)
    exception = Faraday::HTTP.const_get error
    raise exception.new(env)
  end
end

#response_values(env) ⇒ Object



22
23
24
# File 'lib/faraday/raise_errors.rb', line 22

def response_values(env)
  { status: env[:status], headers: env[:response_headers], body: env[:body] }
end