Exception: SeatLayer::APIError
- Defined in:
- lib/seatlayer/errors.rb
Overview
Raised for any non-2xx response.
The API answers failures with "code":…, "message":… and a status.
Surfacing that as one opaque exception leaves every caller string-matching on
error. The subclasses below are the ones an integration actually branches
on — a sold-out seat is a business outcome that belongs in a rescue of its
own, not lumped in with a bad key.
Direct Known Subclasses
AuthError, ConflictError, NotFoundError, RateLimitError, ValidationError
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
The decoded error body, for fields this SDK does not model.
-
#code ⇒ String
readonly
Machine-readable slug: body "code", falling back to "error".
-
#request_id ⇒ String?
readonly
Correlation id from X-Request-ID.
-
#status ⇒ Integer
readonly
HTTP status the API answered with.
Class Method Summary collapse
-
.from_response(status:, body:, request_id:, retry_after:) ⇒ Object
Build the most specific error class for a response.
Instance Method Summary collapse
-
#initialize(status:, code:, body:, request_id:, message: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(status:, code:, body:, request_id:, message: nil) ⇒ APIError
Returns a new instance of APIError.
24 25 26 27 28 29 30 |
# File 'lib/seatlayer/errors.rb', line 24 def initialize(status:, code:, body:, request_id:, message: nil) @status = status @code = code @body = body @request_id = request_id super( || "SeatLayer API error #{status} (#{code})") end |
Instance Attribute Details
#body ⇒ Hash (readonly)
Returns the decoded error body, for fields this SDK does not model.
20 21 22 |
# File 'lib/seatlayer/errors.rb', line 20 def body @body end |
#code ⇒ String (readonly)
Returns machine-readable slug: body "code", falling back to "error".
18 19 20 |
# File 'lib/seatlayer/errors.rb', line 18 def code @code end |
#request_id ⇒ String? (readonly)
Returns correlation id from X-Request-ID. Quote it in support requests.
22 23 24 |
# File 'lib/seatlayer/errors.rb', line 22 def request_id @request_id end |
#status ⇒ Integer (readonly)
Returns HTTP status the API answered with.
16 17 18 |
# File 'lib/seatlayer/errors.rb', line 16 def status @status end |
Class Method Details
.from_response(status:, body:, request_id:, retry_after:) ⇒ Object
Build the most specific error class for a response.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/seatlayer/errors.rb', line 33 def self.from_response(status:, body:, request_id:, retry_after:) code = presence(body["code"]) || presence(body["error"]) || "unknown_error" attrs = { status: status, code: code, body: body, request_id: request_id, message: presence(body["message"]) } case status when 401, 403 then AuthError.new(**attrs) when 404 then NotFoundError.new(**attrs) when 409 then ConflictError.new(**attrs) when 422 then ValidationError.new(**attrs) when 429 then RateLimitError.new(**attrs, retry_after: retry_after) else APIError.new(**attrs) end end |