Exception: GoCardlessPro::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gocardless_pro/error.rb

Overview

A class to represent an API Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ Error

intialize a new error  @param error the error from the API

Raises:

  • (ArgumentError)
[View source]

8
9
10
11
12
# File 'lib/gocardless_pro/error.rb', line 8

def initialize(error)
  raise ArgumentError, 'GoCardless errors expect a hash' unless error.is_a?(Hash)

  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.


4
5
6
# File 'lib/gocardless_pro/error.rb', line 4

def error
  @error
end

Instance Method Details

#codeObject

access the code from the response

[View source]

40
41
42
# File 'lib/gocardless_pro/error.rb', line 40

def code
  @error['code']
end

#documentation_urlObject

access the documentation_url from the response

[View source]

15
16
17
# File 'lib/gocardless_pro/error.rb', line 15

def documentation_url
  @error['documentation_url']
end

#errorsObject

access the errors from the response

[View source]

50
51
52
# File 'lib/gocardless_pro/error.rb', line 50

def errors
  @error.fetch('errors', [])
end

#messageObject

access the message from the response

[View source]

20
21
22
# File 'lib/gocardless_pro/error.rb', line 20

def message
  @error['message']
end

#request_idObject

access the request_id from the response

[View source]

45
46
47
# File 'lib/gocardless_pro/error.rb', line 45

def request_id
  @error['request_id']
end

#to_sObject

[View source]

24
25
26
27
28
29
30
31
32
# File 'lib/gocardless_pro/error.rb', line 24

def to_s
  if errors.any?
    errors
      .map { |err| "#{err['field']} #{err['message']}" }
      .join(', ')
  else
    @error['message']
  end
end

#typeObject

access the type from the response

[View source]

35
36
37
# File 'lib/gocardless_pro/error.rb', line 35

def type
  @error['type']
end