UNPKG

@thalorlabs/errors

Version:

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

26 lines (25 loc) 1.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnauthorizedError = void 0; const types_1 = require("@thalorlabs/types"); const CustomError_1 = __importDefault(require("./CustomError")); /** * Error for authentication failures and unauthorized access. * * Used when users attempt to access resources without proper authentication. * Provides clear 401 error responses with optional authentication context. * * @example * throw new UnauthorizedError('Invalid credentials', 'token-expired', 'req-123'); * * throw new UnauthorizedError('Authentication required', null, 'req-456', { endpoint: '/api/admin' }); */ class UnauthorizedError extends CustomError_1.default { constructor(message = 'Unauthorized', error, requestId, context) { super(types_1.EHttpClientErrorResponse.UNAUTHORIZED, `${message}${error ? `: ${error}` : ''}`, requestId, context); } } exports.UnauthorizedError = UnauthorizedError;