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.



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

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