UNPKG

@thalorlabs/errors

Version:

Enhanced exception handling system for TypeScript applications with comprehensive error classes and debugging capabilities

54 lines (53 loc) 1.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThirdPartyServiceError = void 0; const CustomError_1 = __importDefault(require("./CustomError")); /** * Error for third-party service failures with service context. * * Used when external service calls fail with service-specific error information. * Provides structured third-party service error context with HTTP 502 status by default. * * @example * throw new ThirdPartyServiceError( * 'Payment service unavailable', * 'Stripe', * originalError, * 'req-123', * { statusCode: 503, retryAfter: 30 } * ); * * throw new ThirdPartyServiceError( * 'Email service failed', * 'SendGrid', * undefined, * 'req-456' * ); */ class ThirdPartyServiceError extends CustomError_1.default { constructor(message = 'Third Party Service Error', serviceName, originalError, requestId, context) { // Default to 502 Bad Gateway, but can be overridden via context const statusCode = context?.statusCode || 502; super(statusCode, message, requestId, context); this.serviceName = serviceName; this.originalError = originalError; } getErrorResponse() { const response = super.getErrorResponse(); if (this.serviceName) { response.serviceName = this.serviceName; } if (this.originalError) { response.originalError = { message: this.originalError.message, name: this.originalError.name, stack: this.originalError.stack, }; } return response; } } exports.ThirdPartyServiceError = ThirdPartyServiceError;