Class: FaradayMiddleware::RaiseHttpException

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday/raise_http_exception.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



37
38
39
40
# File 'lib/faraday/raise_http_exception.rb', line 37

def initialize(app)
  super app
  @parser = nil
end

Instance Method Details

#call(env) ⇒ Object



6
7
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
# File 'lib/faraday/raise_http_exception.rb', line 6

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise Taxjar::BadRequest, error_message_400(response)
    when 401
      raise Taxjar::NotAuthorized, error_message_400(response)
    when 403
      raise Taxjar::Forbidden, error_message_400(response)
    when 404
      raise Taxjar::NotFound, error_message_400(response)
    when 405
      raise Taxjar::MethodNotAllowed, error_message_400(response)
    when 406
      raise Taxjar::NotAcceptable, error_message_400(response)
    when 410
      raise Taxjar::Gone, error_message_400(response)
    when 422
      raise Taxjar::UnprocessableEntity, error_message_400(response)
    when 429
      raise Taxjar::TooManyRequests, error_message_400(response)
    when 500
      raise Taxjar::InternalServerError, error_message_500(response, "Something is technically wrong.")
    when 503
      raise Taxjar::ServiceUnavailable, error_message_500(response, "Service is temporarily down for maintenance.")
    when 504
      raise Taxjar::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
    end
  end
end