Exception: GoCardless::ApiError

Inherits:
Error
  • Object
show all
Defined in:
lib/gocardless/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ApiError

Returns a new instance of ApiError.


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gocardless/errors.rb', line 10

def initialize(response)
  @response = response
  @code = response.status

  begin
    parsed_response = MultiJson.decode(response.body)
    errors = parsed_response["error"] || parsed_response["errors"]
    @description = stringify_errors(errors)
  rescue MultiJson::ParseError
    @description = response.body ? response.body.strip : "Unknown error"
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code


8
9
10
# File 'lib/gocardless/errors.rb', line 8

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description


8
9
10
# File 'lib/gocardless/errors.rb', line 8

def description
  @description
end

#responseObject (readonly)

Returns the value of attribute response


8
9
10
# File 'lib/gocardless/errors.rb', line 8

def response
  @response
end

Instance Method Details

#to_sObject


23
24
25
# File 'lib/gocardless/errors.rb', line 23

def to_s
  "#{super} [#{self.code}] #{self.description}"
end