Class: FaradayMiddleware::RaiseHttpException

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

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

Handle response codes 401, 404 and 500 as exceptions. See github.com/technoweenie/faraday#writing-middleware for more details.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/faraday/raise_error.rb', line 9

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 401
      raise Citrulu::AccessDenied, error_message_400(response)
    when 404
      raise Citrulu::NotFound, error_message_400(response)
    when 500
      raise Citrulu::InternalServerError, error_message_500(response, "Something is technically wrong.")
    end
  end
end