Class: Starling::Middlewares::RaiseStarlingErrors
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Starling::Middlewares::RaiseStarlingErrors
- Defined in:
- lib/starling/middlewares/raise_starling_errors.rb
Overview
A Faradfay::Response::Middleware used to raise an {Errors{Errors::ApiError} when the Starling Bank API responds with an HTTP status code indicating an error. The raised error provides access to the response.
Constant Summary collapse
- ERROR_STATUSES =
HTTP status codes which are considered to be an error (alongside non-JSON) responses
400..599
Instance Method Summary collapse
-
#on_complete(env) ⇒ nil
If the response from the Starling Bank API doesn’t indicate an error.
Instance Method Details
#on_complete(env) ⇒ nil
Returns if the response from the Starling Bank API doesn’t indicate an error.
16 17 18 19 |
# File 'lib/starling/middlewares/raise_starling_errors.rb', line 16 def on_complete(env) return unless ERROR_STATUSES.include?(env.status) raise Errors::ApiError, env end |