Class: Percy::Client::Connection::FaradayNiceErrorMiddleware

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/percy/client/connection.rb

Constant Summary collapse

CLIENT_ERROR_STATUS_RANGE =
400...600

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/percy/client/connection.rb', line 10

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 CLIENT_ERROR_STATUS_RANGE
    raise Percy::Client::ClientError.new(
      env, "Got #{env.status} (#{env.method.upcase} #{env.url}):\n#{env.body}")
  end
end