Class: QboApi::RaiseHttpException

Inherits:
Faraday::Response::RaiseError
  • Object
show all
Defined in:
lib/qbo_api/raise_http_exception.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



45
46
47
# File 'lib/qbo_api/raise_http_exception.rb', line 45

def initialize(app)
  super app
end

Instance Method Details

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/qbo_api/raise_http_exception.rb', line 8

def on_complete(env)
  case env[:status]
  when 400
    raise QboApi::BadRequest.new(error_message(env))
  when 401
    raise QboApi::Unauthorized.new(error_message(env))
  when 403
    raise QboApi::Forbidden.new(error_message(env))
  when 404
    raise QboApi::NotFound.new(error_message(env))
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    msg = %(407 "Proxy Authentication Required")
    raise Faraday::ProxyAuthError.new(msg, response_values(env))
  when 409
    raise Faraday::ConflictError, response_values(env)
  when 422
    raise Faraday::UnprocessableEntityError, response_values(env)
  when 429
    raise QboApi::TooManyRequests.new(error_message(env))
  when 500
    raise QboApi::InternalServerError.new(error_message(env))
  when 502
    raise QboApi::BadGateway.new({ error_body: env.reason_phrase })
  when 503
    raise QboApi::ServiceUnavailable.new(error_message(env))
  when 504
    raise QboApi::GatewayTimeout.new(error_message(env))
  when ClientErrorStatuses
    raise Faraday::ClientError, response_values(env)
  when ServerErrorStatuses
    raise Faraday::ServerError, response_values(env)
  when nil
    raise Faraday::NilStatusError, response_values(env)
  end
end