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
#initialize(error) ⇒ Error
intialize a new error @param error the error from the API
8 9 10 11 |
# 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
#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
#code ⇒ Object
access the code from the response
39 40 41 |
# File 'lib/gocardless_pro/error.rb', line 39 def code @error['code'] end |
#documentation_url ⇒ Object
access the documentation_url from the response
14 15 16 |
# File 'lib/gocardless_pro/error.rb', line 14 def documentation_url @error['documentation_url'] end |
#errors ⇒ Object
access the errors from the response
49 50 51 |
# File 'lib/gocardless_pro/error.rb', line 49 def errors @error.fetch('errors', []) end |
#message ⇒ Object
access the message from the response
19 20 21 |
# File 'lib/gocardless_pro/error.rb', line 19 def @error['message'] end |
#request_id ⇒ Object
access the request_id from the response
44 45 46 |
# File 'lib/gocardless_pro/error.rb', line 44 def request_id @error['request_id'] end |
#to_s ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/gocardless_pro/error.rb', line 23 def to_s if errors.any? errors. map { |err| "#{err['field']} #{err['message']}" }. join(', ') else @error['message'] end end |
#type ⇒ Object
access the type from the response
34 35 36 |
# File 'lib/gocardless_pro/error.rb', line 34 def type @error['type'] end |