Exception: Balanced::Error

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

Overview

Custom error class for rescuing from all API response-related Balanced errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.

Parameters:

  • response (Hash)

    the decoded json response body



8
9
10
11
# File 'lib/balanced/error.rb', line 8

def initialize(response)
  @response = response
  super error_message
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#bodyHash

Returns:

  • (Hash)


14
15
16
17
18
19
# File 'lib/balanced/error.rb', line 14

def body
  @body ||= begin
    return {} unless response[:body]
    Utils.hash_with_indifferent_read_access(response[:body])
  end
end

#error_messageObject



21
22
23
24
25
26
27
# File 'lib/balanced/error.rb', line 21

def error_message
  set_attrs
  extra = body[:additional] ? " -- #{body[:additional]}" : ""
  "#{self.class.name}(#{response[:status]})::#{body[:status]}:: "\
  "#{response[:method].to_s.upcase} #{response[:url].to_s}: "\
  "#{body[:category_code]}: #{body[:description]} #{extra}"
end