Exception: Fakturan::WithResponse

Inherits:
Error
  • Object
show all
Defined in:
lib/fakturan_nu/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ex, response = nil) ⇒ WithResponse

Returns a new instance of WithResponse.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fakturan_nu/error.rb', line 15

def initialize(ex, response = nil)
  @wrapped_exception = nil
  @response = response

  if ex.respond_to?(:backtrace) # If ex behaves like an Exception
    super(ex.message)
    @wrapped_exception = ex
  elsif ex.respond_to?(:each_key) # If ex behaves like a Hash
    super("the server responded with status #{ex[:status]} - #{ex[:body]}")
    @response = ex
  else
    super(ex.to_s)
  end
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#backtraceObject



30
31
32
33
34
35
36
# File 'lib/fakturan_nu/error.rb', line 30

def backtrace
  if @wrapped_exception
    @wrapped_exception.backtrace
  else
    super
  end
end

#inspectObject



38
39
40
# File 'lib/fakturan_nu/error.rb', line 38

def inspect
  %(#<#{self.class}>)
end

#statusObject



11
12
13
# File 'lib/fakturan_nu/error.rb', line 11

def status
  response[:status]
end