class GoCardless::ApiError
Attributes
code[R]
description[R]
response[R]
Public Class Methods
new(response)
click to toggle source
# File lib/gocardless/errors.rb, line 10 def initialize(response) @response = response @code = response.status begin parsed_response = MultiJson.decode(response.body) errors = parsed_response["error"] || parsed_response["errors"] @description = stringify_errors(errors) rescue MultiJson::ParseError @description = response.body ? response.body.strip : "Unknown error" end end
Public Instance Methods
to_s()
click to toggle source
# File lib/gocardless/errors.rb, line 23 def to_s "#{super} [#{self.code}] #{self.description}" end
Private Instance Methods
stringify_errors(errors)
click to toggle source
# File lib/gocardless/errors.rb, line 29 def stringify_errors(errors) case errors when Array errors.join(", ") when Hash errors.flat_map do |field, messages| messages.map { |message| "#{field} #{message}" } end.join(", ") else errors.to_s end end