Class: Her::Middleware::MnoeRaiseError

Inherits:
Faraday::Response::RaiseError
  • Object
show all
Defined in:
lib/her_extension/middleware/mnoe_raise_error.rb

Overview

This middleware will raise errors based on the response status Same as Faraday::Response::RaiseError, except it will catch specific errors codes rather than everything in 400..600

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/her_extension/middleware/mnoe_raise_error.rb', line 7

def on_complete(env)
  case env[:status]
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    raise Faraday::Error::ConnectionFailed,
          %(407 "Proxy Authentication Required ")
  when 502..504
    raise Faraday::Error::ConnectionFailed, response_values(env)
  when 401, 500
    raise Faraday::Error::ClientError, response_values(env)
  end
end