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.



25
26
27
28
# File 'lib/faraday/raise_http_exception.rb', line 25

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

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/faraday/raise_http_exception.rb', line 8

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise TPEX::BadRequest, error_message_400(response)
    when 401
      raise TPEX::Unauthorized, error_message_400(response)
    when 404
      raise TPEX::NotFound, error_message_400(response)
    when 406
      raise TPEX::NotAcceptable, error_message_400(response)
    when 500
      raise TPEX::InternalServerError, error_message_500(response, "Internal Server Error.")
    end
  end
end