Exception: Countir::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/countir/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(err, status_code: nil, header: nil, body: nil) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/countir/errors.rb', line 8

def initialize(err, status_code: nil, header: nil, body: nil)
  @cause = err.respond_to?(:backtrace) ? err : nil
  @status_code = status_code
  @header = header.dup unless header.nil?
  @body = JSON.parse(body) rescue body

  message =
    if @body["error"]["message"]
      @body["error"]["message"]
    elsif err.respond_to?(:backtrace)
      err.message
    else
      err.to_s
    end

  super(message)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/countir/errors.rb', line 6

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



5
6
7
# File 'lib/countir/errors.rb', line 5

def header
  @header
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



4
5
6
# File 'lib/countir/errors.rb', line 4

def status_code
  @status_code
end

Instance Method Details

#backtraceObject



26
27
28
29
30
31
32
# File 'lib/countir/errors.rb', line 26

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