Exception: Api::Datadive::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Api::Datadive::Error
- Defined in:
- app/services/api/datadive/error.rb
Overview
Error hierarchy for the DataDive client.
Mirrors the HTTP-status → class mapping used by Taxjar::Error so
callers can rescue a specific failure mode (e.g. +Unauthorized+ for a
bad/expired key, +TooManyRequests+ for rate limiting) or the base
Error for any API failure. Transport / parse failures
are wrapped as ServerError so retry paths still fire.
Defined Under Namespace
Classes: BadRequest, Forbidden, GatewayTimeout, InternalServerError, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity
Constant Summary collapse
- ClientError =
Class.new(self)
- ServerError =
Class.new(self)
- STATUS_MAP =
HTTP status → error class. Statuses outside the map fall back to
ServerError (>= 500) or ClientError. Matches the codes DataDive
documents for the v1 endpoints (400/401/403/404/429/500). { 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 422 => UnprocessableEntity, 429 => TooManyRequests, 500 => InternalServerError, 503 => ServiceUnavailable, 504 => GatewayTimeout }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Integer?
readonly
The HTTP status, or nil for transport errors.
Class Method Summary collapse
-
.from_response(status, body) ⇒ Api::Datadive::Error
Build the appropriate error for a non-2xx response.
Instance Method Summary collapse
-
#initialize(message = '', code = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(message = '', code = nil) ⇒ Error
Returns a new instance of Error.
66 67 68 69 |
# File 'app/services/api/datadive/error.rb', line 66 def initialize( = '', code = nil) super() @code = code end |
Instance Attribute Details
#code ⇒ Integer? (readonly)
Returns the HTTP status, or nil for transport errors.
16 17 18 |
# File 'app/services/api/datadive/error.rb', line 16 def code @code end |
Class Method Details
.from_response(status, body) ⇒ Api::Datadive::Error
Build the appropriate error for a non-2xx response. The message is
taken from DataDive's JSON message (falling back to detail /
error), then a generic "DataDive HTTP ".
57 58 59 60 61 |
# File 'app/services/api/datadive/error.rb', line 57 def from_response(status, body) klass = STATUS_MAP[status] || (status.to_i >= 500 ? ServerError : ClientError) detail = body['message'] || body['detail'] || body['error'] if body.is_a?(Hash) klass.new(detail.presence || "DataDive HTTP #{status}", status) end |