class Bunq::ResponseError

Attributes

body[R]
code[R]
headers[R]

Public Class Methods

new(msg = 'Response error', code: nil, headers: nil, body: nil) click to toggle source
Calls superclass method
# File lib/bunq/errors.rb, line 9
def initialize(msg = 'Response error', code: nil, headers: nil, body: nil)
  @code = code
  @headers = headers || {}
  @body = body
  super("#{msg} (code: #{code}, body: #{body})")
end

Public Instance Methods

errors() click to toggle source

Returns an array of errors returned from the API, or nil if no errors are returned. @return [Array|nil]

# File lib/bunq/errors.rb, line 29
def errors
  json = parsed_body
  json ? json['Error'] : nil
end
parsed_body(opts = {}) click to toggle source

Returns the parsed body if it is a JSON document, nil otherwise. @param opts [Hash] Optional options that are passed to `JSON.parse`.

# File lib/bunq/errors.rb, line 18
def parsed_body(opts = {})
  if @body && @headers['content-type'] && @headers['content-type'].include?('application/json')
    JSON.parse(
      @body,
      opts,
    )
  end
end