Class: FaradayMiddleware::RaiseSageOneException Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Checks the status of the API request and raises relevant exceptions when detected.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise SageOne::BadRequest, error_message(response)
    when 401
      raise SageOne::Unauthorized, error_message(response)
    when 403
      raise SageOne::Forbidden, error_message(response)
    when 404
      raise SageOne::NotFound, error_message(response)
    when 409
      raise SageOne::Conflict, error_message(response)
    when 422
      raise SageOne::UnprocessableEntity, error_message(response)
    end
  end
end