Exception: GoCardlessPro::Error
- Inherits:
-
StandardError
- Object
- StandardError
- GoCardlessPro::Error
- Defined in:
- lib/gocardless_pro/error.rb
Overview
A class to represent an API Error
Direct Known Subclasses
ApiError, GoCardlessError, InvalidApiUsageError, InvalidStateError, ValidationError
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
-
#code ⇒ Object
access the code from the response.
-
#documentation_url ⇒ Object
access the documentation_url from the response.
-
#errors ⇒ Object
access the errors from the response.
-
#initialize(error) ⇒ Error
constructor
intialize a new error @param error the error from the API.
-
#message ⇒ Object
access the message from the response.
-
#request_id ⇒ Object
access the request_id from the response.
- #to_s ⇒ Object
-
#type ⇒ Object
access the type from the response.
Constructor Details
permalink #initialize(error) ⇒ Error
intialize a new error @param error the error from the API
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
permalink #error ⇒ Object (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
permalink #code ⇒ Object
access the code from the response
40 41 42 |
# File 'lib/gocardless_pro/error.rb', line 40 def code @error['code'] end |
permalink #documentation_url ⇒ Object
access the documentation_url from the response
15 16 17 |
# File 'lib/gocardless_pro/error.rb', line 15 def documentation_url @error['documentation_url'] end |
permalink #errors ⇒ Object
access the errors from the response
50 51 52 |
# File 'lib/gocardless_pro/error.rb', line 50 def errors @error.fetch('errors', []) end |
permalink #message ⇒ Object
access the message from the response
20 21 22 |
# File 'lib/gocardless_pro/error.rb', line 20 def @error['message'] end |
permalink #request_id ⇒ Object
access the request_id from the response
45 46 47 |
# File 'lib/gocardless_pro/error.rb', line 45 def request_id @error['request_id'] end |
permalink #to_s ⇒ Object
[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 |
permalink #type ⇒ Object
access the type from the response
35 36 37 |
# File 'lib/gocardless_pro/error.rb', line 35 def type @error['type'] end |