class Starling::Errors::ApiError

An error raised when the Starling Bank API responds in a way indicating an error

Public Instance Methods

error() click to toggle source

@return [String] the error name returned by the Starling Bank API

# File lib/starling/errors/api_error.rb, line 20
def error
  return unless json?
  parsed_body['error']
end
error_description() click to toggle source

@return [String] the error description returned by the Starling Bank API

# File lib/starling/errors/api_error.rb, line 26
def error_description
  return unless json?
  parsed_body['error_description']
end
message() click to toggle source

@return [String] 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)
Calls superclass method
# File lib/starling/errors/api_error.rb, line 10
def message
  # 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
Also aliased as: to_s
parsed_body() click to toggle source

@return [Hash] the parsed JSON response, if there is a valid JSON body @return [nil] if there is no body, or the body is not valid JSON

# File lib/starling/errors/api_error.rb, line 33
def parsed_body
  return unless body
  JSON.parse(body)
rescue JSON::ParserError
  nil
end
to_s()
Alias for: message

Private Instance Methods

json?() click to toggle source
# File lib/starling/errors/api_error.rb, line 42
def json?
  parsed_body
end