Class: PaychexFaradayMiddleWare::RaisePaychexHttpException

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaisePaychexHttpException

Returns a new instance of RaisePaychexHttpException.



5
6
7
# File 'lib/faraday/raise_paychex_http_exception.rb', line 5

def initialize(app)
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/faraday/raise_paychex_http_exception.rb', line 9

def call(env)
  @app.call(env).on_complete do |response|
    case response.status.to_i
    when 400
      raise Paychex::BadRequest, response
    when 401
      raise Paychex::Unauthorized, response
    when 403
      raise Paychex::NoAccess, response
    when 404
      raise Paychex::NotFound, response
    when 500
      raise Paychex::InternalServerError, response
    when 502
      raise Paychex::BadGateway, response
    when 503
      raise Paychex::ServiceUnavailable, response
    when 504
      raise Paychex::GatewayTimeout, response
    end
  end
end