Class: FaradayMiddleware::CloseioErrorHandler

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/closeio/error.rb

Constant Summary collapse

ERROR_STATUSES =
400..600

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/closeio/error.rb', line 13

def on_complete(env)
  case env[:status]
  when 401
    raise Closeio::NotAuthorized, env.body
  when 404
    raise Closeio::NotFound, env.body
  when 429
    raise Closeio::TooManyRequests, env.body
  when 504
    raise Closeio::GatewayTimeout, env.body
  when ERROR_STATUSES
    raise Closeio::Error, "#{env.status}: #{env.body}"
  end
end