Exception: Api::Taxjar::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Api::Taxjar::Error
- Defined in:
- app/services/api/taxjar/error.rb
Overview
Error hierarchy for the direct TaxJar client.
Mirrors the HTTP-status → class mapping that the taxjar-ruby gem
exposed (Taxjar::Error::NotFound, …::UnprocessableEntity,
…::ServerError, …::Forbidden, …) so the existing rescue clauses in
the submit/sync services keep working unchanged after the port.
Defined Under Namespace
Classes: BadRequest, Forbidden, GatewayTimeout, Gone, InternalServerError, MethodNotAllowed, NotAcceptable, 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. { 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 405 => MethodNotAllowed, 406 => NotAcceptable, 410 => Gone, 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::Taxjar::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.
69 70 71 72 |
# File 'app/services/api/taxjar/error.rb', line 69 def initialize( = '', code = nil) super() @code = code end |
Instance Attribute Details
#code ⇒ Integer? (readonly)
Returns the HTTP status, or nil for transport errors.
15 16 17 |
# File 'app/services/api/taxjar/error.rb', line 15 def code @code end |
Class Method Details
.from_response(status, body) ⇒ Api::Taxjar::Error
Build the appropriate error for a non-2xx response. The message is
taken from TaxJar's JSON detail (falling back to error).
60 61 62 63 64 |
# File 'app/services/api/taxjar/error.rb', line 60 def from_response(status, body) klass = STATUS_MAP[status] || (status.to_i >= 500 ? ServerError : ClientError) detail = body['detail'] || body['error'] if body.is_a?(Hash) klass.new(detail.presence || "TaxJar HTTP #{status}", status) end |