UNPKG

@eleva-io/erp-sdk

Version:

SDK oficial para el ERP de Eleva

52 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoteElevaError = void 0; const errors_1 = require("./errors"); /** * An `ElevaError` enriched with the context of a failed remote call. * Not tied to HTTP — covers any outbound call (HTTP, gRPC, message queues, etc.) * where capturing the outgoing request and incoming response aids debugging. * * `ReqM` / `ResM` type the transport metadata for the request and response respectively; * both default to `Record<string, unknown>` for untyped usage. * * @example * type HttpHeaders = Record<string, string> * const err = RemoteElevaError.from<ErrorCode, HttpHeaders, HttpHeaders>(body, req, res) * err.request.metadata?.['authorization'] // string */ class RemoteElevaError extends errors_1.ElevaError { /** Context about the outgoing call that produced this error. */ request; /** Context about the response that contained or triggered the error. */ response; constructor(args) { super(args); this.name = 'RemoteElevaError'; this.request = args.request; this.response = args.response; } /** Full serialisation including remote call request and response context. */ toJSON() { return { ...super.toJSON(), request: this.request, response: this.response, }; } /** Narrows to `RemoteElevaError<K, ReqM, ResM>`, preserving metadata types on the narrowed type. */ is(code) { return super.is(code); } /** * Builds a `RemoteElevaError` from a raw response payload and remote call context. * Delegates payload parsing to `ElevaError._parsePayload()`; malformed payloads become `INTERNAL_SERVER_ERROR`. * `cause` takes precedence over any cause inferred from the payload. */ static from(body, request, response, cause) { const parsed = errors_1.ElevaError._parsePayload(body); return new RemoteElevaError({ ...parsed, cause: cause ?? parsed.cause, request, response }); } } exports.RemoteElevaError = RemoteElevaError; //# sourceMappingURL=errors_remote.js.map