Exception: PaymentKit::Error
- Inherits:
-
StandardError
- Object
- StandardError
- PaymentKit::Error
- Defined in:
- lib/payment_kit/errors.rb
Overview
Base error for all PaymentKit failures.
PaymentKit returns RFC 7807 problem documents. Standard members (+title+,
detail, status, instance, request_id) plus any extension members are
kept in problem so callers can branch on them without re-parsing the body.
Transient failures carry a top-level error_code and retryable: true
(for example invoice_locked on HTTP 409).
Direct Known Subclasses
APIConnectionError, APIError, AuthenticationError, CardError, ConflictError, InvalidRequestError, RateLimitError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Raw response body as received.
-
#error_code ⇒ Object
readonly
Machine-readable code such as
invoice_locked, when PaymentKit sends one. -
#problem ⇒ Object
readonly
Parsed RFC 7807 problem document as a Hash; empty when the body was not JSON.
-
#request_id ⇒ Object
readonly
PaymentKit request id, from the problem document or the
Request-Idheader. -
#status ⇒ Object
readonly
HTTP status of the failing response, or
nilfor client-side failures.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Reads an RFC 7807 extension member, e.g.
-
#initialize(message = nil, status: nil, body: nil, request_id: nil, error_code: nil, retryable: nil) ⇒ Error
constructor
Any attribute not passed explicitly is read from the RFC 7807
body. -
#invoice_id ⇒ Object
Convenience reader for the
invoice_idextension member, when present. -
#retryable? ⇒ Boolean
Whether PaymentKit marked this failure as safe to retry unchanged.
-
#subscription_id ⇒ Object
Convenience reader for the
subscription_idextension member, when present.
Constructor Details
#initialize(message = nil, status: nil, body: nil, request_id: nil, error_code: nil, retryable: nil) ⇒ Error
Any attribute not passed explicitly is read from the RFC 7807 body.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/payment_kit/errors.rb', line 31 def initialize( = nil, status: nil, body: nil, request_id: nil, error_code: nil, retryable: nil) @status = status @body = body @problem = parse_problem(body) @request_id = request_id || @problem["request_id"] @error_code = error_code || @problem["error_code"] @retryable = retryable.nil? ? @problem["retryable"] : retryable super() end |
Instance Attribute Details
#body ⇒ Object (readonly)
Raw response body as received.
19 20 21 |
# File 'lib/payment_kit/errors.rb', line 19 def body @body end |
#error_code ⇒ Object (readonly)
Machine-readable code such as invoice_locked, when PaymentKit sends one.
25 26 27 |
# File 'lib/payment_kit/errors.rb', line 25 def error_code @error_code end |
#problem ⇒ Object (readonly)
Parsed RFC 7807 problem document as a Hash; empty when the body was not JSON.
28 29 30 |
# File 'lib/payment_kit/errors.rb', line 28 def problem @problem end |
#request_id ⇒ Object (readonly)
PaymentKit request id, from the problem document or the Request-Id header.
22 23 24 |
# File 'lib/payment_kit/errors.rb', line 22 def request_id @request_id end |
#status ⇒ Object (readonly)
HTTP status of the failing response, or nil for client-side failures.
16 17 18 |
# File 'lib/payment_kit/errors.rb', line 16 def status @status end |
Instance Method Details
#[](key) ⇒ Object
Reads an RFC 7807 extension member, e.g. error["invoice_id"].
48 49 50 |
# File 'lib/payment_kit/errors.rb', line 48 def [](key) @problem[key.to_s] end |
#invoice_id ⇒ Object
Convenience reader for the invoice_id extension member, when present.
53 54 55 |
# File 'lib/payment_kit/errors.rb', line 53 def invoice_id self["invoice_id"] end |
#retryable? ⇒ Boolean
Whether PaymentKit marked this failure as safe to retry unchanged.
43 44 45 |
# File 'lib/payment_kit/errors.rb', line 43 def retryable? @retryable == true end |
#subscription_id ⇒ Object
Convenience reader for the subscription_id extension member, when present.
58 59 60 |
# File 'lib/payment_kit/errors.rb', line 58 def subscription_id self["subscription_id"] end |