Exception: Nfe::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Nfe::Error
- Defined in:
- lib/nfe/errors.rb,
sig/nfe/errors.rbs
Overview
Base class for every error the SDK raises.
All SDK errors derive from Error, so consumer code can catch the
whole family with a single rescue Nfe::Error. Errors derived from an HTTP
response carry the response context (+status_code+, request_id,
error_code, response_body, response_headers) for diagnostics.
#to_h returns a logging-safe Hash that deliberately omits the raw response body and headers, which may carry secrets or PII.
Direct Known Subclasses
ApiConnectionError, AuthenticationError, AuthorizationError, ConfigurationError, ConflictError, InvalidRequestError, InvoiceProcessingError, NotFoundError, RateLimitError, ServerError, SignatureVerificationError
Instance Attribute Summary collapse
-
#error_code ⇒ String?
readonly
Machine-readable error code from the body.
-
#request_id ⇒ String?
readonly
Server-supplied request/correlation id.
-
#response_body ⇒ String?
readonly
Raw response body, for programmatic inspection.
-
#response_headers ⇒ Hash
readonly
Response headers (lowercase keys).
-
#status_code ⇒ Integer?
readonly
HTTP status code, when derived from a response.
Instance Method Summary collapse
-
#initialize(message = nil, status_code: nil, request_id: nil, error_code: nil, response_body: nil, response_headers: {}) ⇒ Error
constructor
A new instance of Error.
-
#to_h ⇒ Hash
Logging-safe representation.
Constructor Details
#initialize(message = nil, status_code: nil, request_id: nil, error_code: nil, response_body: nil, response_headers: {}) ⇒ Error
Returns a new instance of Error.
31 32 33 34 35 36 37 38 39 |
# File 'lib/nfe/errors.rb', line 31 def initialize( = nil, status_code: nil, request_id: nil, error_code: nil, response_body: nil, response_headers: {}) super() @status_code = status_code @request_id = request_id @error_code = error_code @response_body = response_body @response_headers = response_headers || {} end |
Instance Attribute Details
#error_code ⇒ String? (readonly)
Returns machine-readable error code from the body.
19 20 21 |
# File 'lib/nfe/errors.rb', line 19 def error_code @error_code end |
#request_id ⇒ String? (readonly)
Returns server-supplied request/correlation id.
17 18 19 |
# File 'lib/nfe/errors.rb', line 17 def request_id @request_id end |
#response_body ⇒ String? (readonly)
Returns raw response body, for programmatic inspection.
21 22 23 |
# File 'lib/nfe/errors.rb', line 21 def response_body @response_body end |
#response_headers ⇒ Hash (readonly)
Returns response headers (lowercase keys).
23 24 25 |
# File 'lib/nfe/errors.rb', line 23 def response_headers @response_headers end |
#status_code ⇒ Integer? (readonly)
Returns HTTP status code, when derived from a response.
15 16 17 |
# File 'lib/nfe/errors.rb', line 15 def status_code @status_code end |
Instance Method Details
#to_h ⇒ Hash
Logging-safe representation. Never includes raw headers or body, which could leak the API key, certificate password, or PII.
45 46 47 48 49 50 51 52 53 |
# File 'lib/nfe/errors.rb', line 45 def to_h { type: self.class.name, message: , status_code: status_code, request_id: request_id, error_code: error_code } end |