Class: ContextIO::Response::RaiseClientError Private
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- ContextIO::Response::RaiseClientError
- 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
Instance Method Summary collapse
-
#on_complete(env) ⇒ void
private
Raise an error if the response has a 4xx status code.
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
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 |