@decaf-ts/core
Version:
Core persistence module for the decaf framework
69 lines • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectionError = exports.ForbiddenError = exports.AuthorizationError = void 0;
const db_decorators_1 = require("@decaf-ts/db-decorators");
/**
* @description Error thrown when a user is not authorized to perform an action
* @summary This error is thrown when a user attempts to access a resource or perform an action without proper authentication
* @param {string|Error} msg - The error message or Error object
* @class AuthorizationError
* @category Errors
* @example
* ```typescript
* // Example of throwing an AuthorizationError
* if (!user.isAuthenticated()) {
* throw new AuthorizationError('User not authenticated');
* }
* ```
*/
class AuthorizationError extends db_decorators_1.BadRequestError {
constructor(msg, name = AuthorizationError.name, code = 401) {
super(msg, name, code);
}
}
exports.AuthorizationError = AuthorizationError;
/**
* @description Error thrown when a user is forbidden from accessing a resource
* @summary This error is thrown when an authenticated user attempts to access a resource or perform an action they don't have permission for
* @param {string|Error} msg - The error message or Error object
* @return {void}
* @class ForbiddenError
* @category Errors
* @example
* ```typescript
* // Example of throwing a ForbiddenError
* if (!user.hasPermission('admin')) {
* throw new ForbiddenError('User does not have admin permissions');
* }
* ```
*/
class ForbiddenError extends AuthorizationError {
constructor(msg, name = ForbiddenError.name) {
super(msg, name, 403);
}
}
exports.ForbiddenError = ForbiddenError;
/**
* @description Error thrown when a connection to a service fails
* @summary This error is thrown when the application fails to establish a connection to a required service or resource
* @param {string|Error} msg - The error message or Error object
* @return {void}
* @class ConnectionError
* @category Errors
* @example
* ```typescript
* // Example of throwing a ConnectionError
* try {
* await database.connect();
* } catch (error) {
* throw new ConnectionError('Failed to connect to database');
* }
* ```
*/
class ConnectionError extends db_decorators_1.InternalError {
constructor(msg) {
super(msg, ConnectionError.name, 503);
}
}
exports.ConnectionError = ConnectionError;
//# sourceMappingURL=errors.js.map