Exception: SmartcarError

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

Overview

Custom SmartcarError class to represent errors from Smartcar APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, headers) ⇒ SmartcarError

Returns a new instance of SmartcarError.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smartcar_error.rb', line 7

def initialize(status, body, headers)
  @status_code = status
  if body.is_a?(String)
    super(body)
    @request_id = headers['sc-request-id']
    return
  end
  @retry_after = headers['retry-after']
  body = coerce_attributes(body)

  super("#{body[:type]}:#{body[:code]} - #{body[:description]}")
  @request_id = body[:requestId] || headers['sc-request-id']
  set_attributes(body)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#detailObject (readonly)

Returns the value of attribute detail.



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

def detail
  @detail
end

#doc_urlObject (readonly)

Returns the value of attribute doc_url.



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

def doc_url
  @doc_url
end

#request_idObject (readonly)

Returns the value of attribute request_id.



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

def request_id
  @request_id
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



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

def resolution
  @resolution
end

#retry_afterObject (readonly)

Returns the value of attribute retry_after.



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

def retry_after
  @retry_after
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



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

def status_code
  @status_code
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end