class GoCardlessPro::Error
A class to represent an API Error
Attributes
error[R]
Public Class Methods
new(error)
click to toggle source
intialize a new error @param error the error from the API
# 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
Public Instance Methods
code()
click to toggle source
access the code from the response
# File lib/gocardless_pro/error.rb, line 39 def code @error['code'] end
documentation_url()
click to toggle source
access the documentation_url
from the response
# File lib/gocardless_pro/error.rb, line 14 def documentation_url @error['documentation_url'] end
errors()
click to toggle source
access the errors from the response
# File lib/gocardless_pro/error.rb, line 49 def errors @error.fetch('errors', []) end
message()
click to toggle source
access the message from the response
# File lib/gocardless_pro/error.rb, line 19 def message @error['message'] end
request_id()
click to toggle source
access the request_id
from the response
# File lib/gocardless_pro/error.rb, line 44 def request_id @error['request_id'] end
to_s()
click to toggle source
# 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()
click to toggle source
access the type from the response
# File lib/gocardless_pro/error.rb, line 34 def type @error['type'] end