Exception: Ibanity::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, ibanity_request_id) ⇒ Error

Returns a new instance of Error.



5
6
7
8
# File 'lib/ibanity/error.rb', line 5

def initialize(errors, ibanity_request_id)
  @errors = errors
  @ibanity_request_id = ibanity_request_id
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/ibanity/error.rb', line 3

def errors
  @errors
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ibanity/error.rb', line 10

def to_s
  if @errors.is_a?(Array) && @errors.size > 0
    formatted_errors = @errors.map do |error|
      if error["meta"] && error["meta"]["attribute"]
        "* #{error["code"]}: '#{error["meta"]["attribute"]}' #{error["detail"]}"
      elsif error["meta"] && error["meta"]["resource"]
        "* #{error["code"]}: '#{error["meta"]["resource"]}' #{error["detail"]}"
      else
        "* #{error["code"]}: #{error["detail"]}"
      end
    end
    formatted_errors << "* ibanity_request_id: #{@ibanity_request_id}"
    formatted_errors.join("\n")
  elsif @errors.is_a?(Hash)
    "* #{@errors["error"]}: #{@errors["error_description"]}\n * Error hint: #{@errors["error_hint"]}\n * ibanity_request_id: #{@ibanity_request_id}"
  elsif @errors.is_a?(String)
    @errors
  else
    super
  end
end