Exception: Zazu::Error

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

Overview

Base class for every Zazu SDK error.

Carries the HTTP status, the API request id (header ‘X-Request-Id`), the parsed error type from the API (`error.type`), and the raw response body so callers can introspect anything the SDK didn’t explicitly model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, status: nil, request_id: nil, type: nil, param: nil, body: nil) ⇒ Error

Returns a new instance of Error.



13
14
15
16
17
18
19
20
# File 'lib/zazu/errors.rb', line 13

def initialize(message = nil, status: nil, request_id: nil, type: nil, param: nil, body: nil)
  super(message)
  @status = status
  @request_id = request_id
  @type = type
  @param = param
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/zazu/errors.rb', line 11

def body
  @body
end

#paramObject (readonly)

Returns the value of attribute param.



11
12
13
# File 'lib/zazu/errors.rb', line 11

def param
  @param
end

#request_idObject (readonly)

Returns the value of attribute request_id.



11
12
13
# File 'lib/zazu/errors.rb', line 11

def request_id
  @request_id
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/zazu/errors.rb', line 11

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/zazu/errors.rb', line 11

def type
  @type
end

Instance Method Details

#to_hObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/zazu/errors.rb', line 22

def to_h
  {
    error: self.class.name.split("::").last,
    message:,
    status:,
    request_id:,
    type:,
    param:
  }.compact
end