Class: Tacokit::Middleware::Boom

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/tacokit/middleware/boom.rb

Constant Summary collapse

CLIENT_ERROR_STATUSES =
400...600

Instance Method Summary collapse

Instance Method Details

#error_message(env) ⇒ Object


20
21
22
# File 'lib/tacokit/middleware/boom.rb', line 20

def error_message(env)
  "Server returned #{env[:status]}: #{env.body}. Headers #{env.response_headers.inspect}"
end

#on_complete(env) ⇒ Object


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

def on_complete(env)
  case env[:status]
  when 401
    raise Tacokit::Error::Unauthorized, error_message(env)
  when 404
    raise Tacokit::Error::ResourceNotFound, error_message(env)
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    raise Tacokit::Error::ConnectionFailed, %(407 "Proxy Authentication Required ")
  when CLIENT_ERROR_STATUSES
    raise Tacokit::Error::ClientError, error_message(env)
  end
end