Exception: DwollaV2::Error

Inherits:
StandardError
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dwolla_v2/error.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



19
20
21
# File 'lib/dwolla_v2/error.rb', line 19

def initialize response
  @response = response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/dwolla_v2/error.rb', line 47

def method_missing method, *args, &block
  if response_body.respond_to? method
    response_body.public_send method, *args, &block
  else
    super
  end
end

Class Method Details

.raise!(response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dwolla_v2/error.rb', line 8

def self.raise! response
  unless response.respond_to? :body
    response = turn_into_response(response)
  end
  if response.body.is_a?(Hash) && klass = error_class(response.body[:error] || response.body[:code])
    raise klass, response, caller
  else
    raise self, response, caller
  end
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/dwolla_v2/error.rb', line 43

def == other
  super || response_body == other
end

#headersObject



23
24
25
26
27
28
29
# File 'lib/dwolla_v2/error.rb', line 23

def headers
  if @response.respond_to? :response_headers
    @response.response_headers
  elsif @response.respond_to? :headers
    @response.headers
  end
end

#inspectObject



63
64
65
# File 'lib/dwolla_v2/error.rb', line 63

def inspect
  Util.pretty_inspect self.class.name, { status: status, headers: headers }, response_body
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dwolla_v2/error.rb', line 35

def is_a? klass
  super || response_body.is_a?(klass)
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/dwolla_v2/error.rb', line 39

def kind_of? klass
  super || response_body.kind_of?(klass)
end

#messageObject



55
56
57
# File 'lib/dwolla_v2/error.rb', line 55

def message
  to_s
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dwolla_v2/error.rb', line 31

def respond_to? method, include_private = false
  super || response_body.respond_to?(method)
end

#to_strObject



59
60
61
# File 'lib/dwolla_v2/error.rb', line 59

def to_str
  nil
end