Class: ContextIO::Response::RaiseClientError Private

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/context-io/response/raise_client_error.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.

Faraday middleware for raising errors on 4xx HTTP status codes

API:

  • private

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ void

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.

This method returns an undefined value.

Raise an error if the response has a 4xx status code

Raises:

  • If the response has a 4xx status code.

  • If the response has a 400 status code.

  • If the response has a 401 status code.

  • If the response has a 402 status code.

  • If the response has a 403 status code.

  • If the response has a 404 status code.

API:

  • private



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/context-io/response/raise_client_error.rb', line 30

def on_complete(env)
  case env[:status].to_i
  when 400
    raise ContextIO::Error::BadRequest.new(error_body(env[:body]), env[:response_headers])
  when 401
    raise ContextIO::Error::Unauthorized.new(error_body(env[:body]), env[:response_headers])
  when 402
    raise ContextIO::Error::PaymentRequired.new(error_body(env[:body]), env[:response_headers])
  when 403
    raise ContextIO::Error::Forbidden.new(error_body(env[:body]), env[:response_headers])
  when 404
    raise ContextIO::Error::NotFound.new(error_body(env[:body]), env[:response_headers])
  end
end