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



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

def initialize(response)
  @response = response
  @code = response.status
  body = MultiJson.decode(response.body) rescue nil
  if body.is_a? Hash
    @description = body["error"] || response.body.strip || "Unknown error"
  end
end

Instance Attribute Details

#code ⇒ Object (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#description ⇒ Object (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#response ⇒ Object (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#to_s ⇒ Object



20
21
22
# File 'lib/gocardless/errors.rb', line 20

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