Exception: KnoxCall::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/knoxcall/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code, headers: nil, body: nil, code: nil, request_id: nil) ⇒ APIError

Returns a new instance of APIError.



27
28
29
30
31
32
33
34
# File 'lib/knoxcall/errors.rb', line 27

def initialize(message, status_code, headers: nil, body: nil, code: nil, request_id: nil)
  super("KnoxCall API error #{status_code}: #{message}")
  @status_code = status_code
  @headers = headers || {}
  @body = body
  @code = code
  @request_id = request_id
end

Instance Attribute Details

#body ⇒ Object (readonly)

Returns the value of attribute body.



18
19
20
# File 'lib/knoxcall/errors.rb', line 18

def body
  @body
end

#code ⇒ Object (readonly)

Machine-readable error code — the server envelope's error.type (Shape A) or the bare error code string (flat Shape C). nil when the body carried no code. Branch on this rather than string-matching the message.



22
23
24
# File 'lib/knoxcall/errors.rb', line 22

def code
  @code
end

#headers ⇒ Object (readonly)

Returns the value of attribute headers.



18
19
20
# File 'lib/knoxcall/errors.rb', line 18

def headers
  @headers
end

#request_id ⇒ Object (readonly)

Correlation id for KnoxCall server logs — the X-Request-Id response header when present, else the id carried in the body. nil if neither.



25
26
27
# File 'lib/knoxcall/errors.rb', line 25

def request_id
  @request_id
end

#status_code ⇒ Object (readonly)

Returns the value of attribute status_code.



18
19
20
# File 'lib/knoxcall/errors.rb', line 18

def status_code
  @status_code
end

Instance Method Details

#type ⇒ Object

Alias for #code — the canonical /v1 envelope names this field type, so callers that think in server terms can read e.type.



38
# File 'lib/knoxcall/errors.rb', line 38

def type = @code