Exception: KnoxCall::APIError
- Defined in:
- lib/knoxcall/errors.rb
Direct Known Subclasses
AIGatewayError, AuthenticationError, ConflictError, NotFoundError, PaymentRequiredError, PermissionDeniedError, RateLimitError, ServerError, ValidationError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Machine-readable error code — the server envelope's
error.type(Shape A) or the bareerrorcode string (flat Shape C). -
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request_id ⇒ Object
readonly
Correlation id for KnoxCall server logs — the
X-Request-Idresponse header when present, else the id carried in the body. -
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(message, status_code, headers: nil, body: nil, code: nil, request_id: nil) ⇒ APIError
constructor
A new instance of APIError.
-
#type ⇒ Object
Alias for #code — the canonical /v1 envelope names this field
type, so callers that think in server terms can reade.type.
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(, 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 |