jsm-exceptions
Version:
A comprehensive TypeScript exception library with HTTP status code support, detailed JSDoc documentation, and backward compatibility. Provides structured error handling for web applications and APIs.
36 lines (35 loc) • 1.26 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_exception_1 = __importDefault(require("./base.exception"));
/**
* @fileoverview Unauthorized exception (HTTP 401)
* @author dr. Salmi <reevosolutions@gmail.com>
*/
/**
* Exception thrown when authentication is required but not provided or invalid.
* Corresponds to HTTP 401 Unauthorized status code.
*
* @class UnauthorizedException
* @extends {BaseException}
* @example
* ```typescript
* throw new UnauthorizedException('Invalid credentials');
* throw new UnauthorizedException('Token expired', { tokenType: 'access' });
* ```
*/
class UnauthorizedException extends base_exception_1.default {
/**
* Creates an instance of UnauthorizedException.
*
* @param {string} [message='Unauthorized'] - The error message
* @param {Record<string, any>} [context] - Additional context about the authorization failure
* @memberof UnauthorizedException
*/
constructor(message = 'Unauthorized', context) {
super(message, 401, context);
}
}
exports.default = UnauthorizedException;
;