Exception: Starling::Errors::ApiError
- Defined in:
- lib/starling/errors/api_error.rb
Overview
An error raised when the Starling Bank API responds in a way indicating an error
Instance Method Summary collapse
-
#error ⇒ String
The error name returned by the Starling Bank API.
-
#error_description ⇒ String
The error description returned by the Starling Bank API.
-
#message ⇒ String
(also: #to_s)
A helpful message explaining the error, incorporating the HTTP status code and the error message (either parsed from the JSON for a JSON response, or the whole body).
- #parsed_body ⇒ Hash?
Methods inherited from BaseError
Constructor Details
This class inherits a constructor from Starling::Errors::BaseError
Instance Method Details
#error ⇒ String
Returns the error name returned by the Starling Bank API.
20 21 22 23 |
# File 'lib/starling/errors/api_error.rb', line 20 def error return unless json? parsed_body['error'] end |
#error_description ⇒ String
Returns the error description returned by the Starling Bank API.
26 27 28 29 |
# File 'lib/starling/errors/api_error.rb', line 26 def error_description return unless json? parsed_body['error_description'] end |
#message ⇒ String Also known as: to_s
Returns a helpful message explaining the error, incorporating the HTTP status code and the error message (either parsed from the JSON for a JSON response, or the whole body).
10 11 12 13 14 15 16 |
# File 'lib/starling/errors/api_error.rb', line 10 def # If there response isn't JSON or either the Starling-provided error or error # description is missing, return a simpler error from BaseError return super unless error && error_description "#{status}: #{error_description} (#{error})" end |
#parsed_body ⇒ Hash?
33 34 35 36 37 38 |
# File 'lib/starling/errors/api_error.rb', line 33 def parsed_body return unless body JSON.parse(body) rescue JSON::ParserError nil end |