Class: Starling::Middlewares::RaiseStarlingErrors

Inherits:
Faraday::Response::Middleware
  • Object
show all
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

Instance Method Details

#on_complete(env) ⇒ nil

Returns if the response from the Starling Bank API doesn’t indicate an error.

Parameters:

  • env

    The Faraday environment, providing access to the response

Returns:

  • (nil)

    if the response from the Starling Bank API doesn’t indicate an error

Raises:

  • (Errors::ApiError)

    if the response from the Starling Bank API indicates 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