Exception: VisionAPI::APIError
- Defined in:
- lib/vision_api/errors.rb
Overview
A structured failure from the API.
Every failure carries the same envelope — {"error": {code, message, details?}}
— and code is contract while message is prose that changes. Rescue the class you
mean, or switch on code; never branch on the message text.
Direct Known Subclasses
AuthenticationError, ConflictError, InsufficientCreditsError, InternalError, InvalidRequestError, NotFoundError, PayloadTooLargeError, PermissionDeniedError, ProviderError, RateLimitError, ResultExpiredError, SyncTimeoutError, UnprocessableError, UnsupportedTypeError
Constant Summary collapse
- RETRYABLE_CODES =
"too_many_tasks" is 429 but absent on purpose: it clears when the caller's own task finishes, so an automatic sleep-and-retry would block the very thing it waits for.
%w[rate_limited internal_error provider_error].freeze
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
The stable machine-readable value from the envelope.
-
#details ⇒ Hash
readonly
Whatever the endpoint attached: +required+/+available+ on 402,
request_idon 500,max_pageson 413. -
#headers ⇒ Hash
readonly
The response headers, lower-cased.
-
#request_id ⇒ String?
readonly
The correlation id.
-
#status ⇒ Integer
readonly
The HTTP status.
Instance Method Summary collapse
-
#initialize(status:, code:, message:, details: nil, headers: nil) ⇒ APIError
constructor
A new instance of APIError.
-
#retryable? ⇒ Boolean
Whether the identical call could plausibly succeed on a second attempt.
Constructor Details
#initialize(status:, code:, message:, details: nil, headers: nil) ⇒ APIError
Returns a new instance of APIError.
34 35 36 37 38 39 40 41 |
# File 'lib/vision_api/errors.rb', line 34 def initialize(status:, code:, message:, details: nil, headers: nil) super("#{code}: #{}") @status = status @code = code @details = details || {} @headers = headers || {} @request_id = @details["request_id"] || @headers["x-request-id"] end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns the stable machine-readable value from the envelope.
25 26 27 |
# File 'lib/vision_api/errors.rb', line 25 def code @code end |
#details ⇒ Hash (readonly)
Returns whatever the endpoint attached: +required+/+available+ on 402,
request_id on 500, max_pages on 413.
28 29 30 |
# File 'lib/vision_api/errors.rb', line 28 def details @details end |
#headers ⇒ Hash (readonly)
Returns the response headers, lower-cased.
30 31 32 |
# File 'lib/vision_api/errors.rb', line 30 def headers @headers end |
#request_id ⇒ String? (readonly)
Returns the correlation id. Quote it in support requests.
32 33 34 |
# File 'lib/vision_api/errors.rb', line 32 def request_id @request_id end |
#status ⇒ Integer (readonly)
Returns the HTTP status.
23 24 25 |
# File 'lib/vision_api/errors.rb', line 23 def status @status end |
Instance Method Details
#retryable? ⇒ Boolean
Whether the identical call could plausibly succeed on a second attempt. False for
every input error, and for insufficient_credits — no amount of retrying changes a
balance.
46 47 48 |
# File 'lib/vision_api/errors.rb', line 46 def retryable? RETRYABLE_CODES.include?(code) end |