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.
200 lines (199 loc) • 12 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JWTTokenExpired = exports.InternalServerError = exports.JsmException = exports.ServiceUnavailableException = exports.NotImplementedException = exports.TooManyRequestsException = exports.RequestTimeoutException = exports.MethodNotAllowedException = exports.ForbiddenException = exports.JWTTokenExpiredException = exports.ValidationException = exports.InternalServerErrorException = exports.ValueAlreadyExistsException = exports.UnauthorizedException = exports.NoContentException = exports.NoItemsFoundException = exports.ItemNotFoundException = exports.InvalidPasswordException = exports.UnprocessableEntityException = exports.BadRequestException = exports.BaseException = void 0;
// New imports with proper naming
const base_exception_1 = __importDefault(require("./base.exception"));
const bad_request_exception_1 = __importDefault(require("./bad-request.exception"));
const unprocessable_entity_exception_1 = __importDefault(require("./unprocessable-entity.exception"));
const invalid_password_exception_1 = __importDefault(require("./invalid-password.exception"));
const item_not_found_exception_1 = __importDefault(require("./item-not-found.exception"));
const no_items_found_exception_1 = __importDefault(require("./no-items-found.exception"));
const no_content_exception_1 = __importDefault(require("./no-content.exception"));
const unauthorized_error_exception_1 = __importDefault(require("./unauthorized-error.exception"));
const value_already_exists_exception_1 = __importDefault(require("./value-already-exists.exception"));
const jsm_exception_exception_1 = __importDefault(require("./jsm-exception.exception"));
const internal_server_error_exception_1 = __importDefault(require("./internal-server-error.exception"));
const validation_exception_1 = __importDefault(require("./validation.exception"));
const jwt_token_expired_exception_1 = __importDefault(require("./jwt-token-expired.exception"));
const forbidden_exception_1 = __importDefault(require("./forbidden.exception"));
const method_not_allowed_exception_1 = __importDefault(require("./method-not-allowed.exception"));
const request_timeout_exception_1 = __importDefault(require("./request-timeout.exception"));
const too_many_requests_exception_1 = __importDefault(require("./too-many-requests.exception"));
const not_implemented_exception_1 = __importDefault(require("./not-implemented.exception"));
const service_unavailable_exception_1 = __importDefault(require("./service-unavailable.exception"));
// Export new exceptions with proper names
var base_exception_2 = require("./base.exception");
Object.defineProperty(exports, "BaseException", { enumerable: true, get: function () { return __importDefault(base_exception_2).default; } });
var bad_request_exception_2 = require("./bad-request.exception");
Object.defineProperty(exports, "BadRequestException", { enumerable: true, get: function () { return __importDefault(bad_request_exception_2).default; } });
var unprocessable_entity_exception_2 = require("./unprocessable-entity.exception");
Object.defineProperty(exports, "UnprocessableEntityException", { enumerable: true, get: function () { return __importDefault(unprocessable_entity_exception_2).default; } });
var invalid_password_exception_2 = require("./invalid-password.exception");
Object.defineProperty(exports, "InvalidPasswordException", { enumerable: true, get: function () { return __importDefault(invalid_password_exception_2).default; } });
var item_not_found_exception_2 = require("./item-not-found.exception");
Object.defineProperty(exports, "ItemNotFoundException", { enumerable: true, get: function () { return __importDefault(item_not_found_exception_2).default; } });
var no_items_found_exception_2 = require("./no-items-found.exception");
Object.defineProperty(exports, "NoItemsFoundException", { enumerable: true, get: function () { return __importDefault(no_items_found_exception_2).default; } });
var no_content_exception_2 = require("./no-content.exception");
Object.defineProperty(exports, "NoContentException", { enumerable: true, get: function () { return __importDefault(no_content_exception_2).default; } });
var unauthorized_error_exception_2 = require("./unauthorized-error.exception");
Object.defineProperty(exports, "UnauthorizedException", { enumerable: true, get: function () { return __importDefault(unauthorized_error_exception_2).default; } });
var value_already_exists_exception_2 = require("./value-already-exists.exception");
Object.defineProperty(exports, "ValueAlreadyExistsException", { enumerable: true, get: function () { return __importDefault(value_already_exists_exception_2).default; } });
var internal_server_error_exception_2 = require("./internal-server-error.exception");
Object.defineProperty(exports, "InternalServerErrorException", { enumerable: true, get: function () { return __importDefault(internal_server_error_exception_2).default; } });
var validation_exception_2 = require("./validation.exception");
Object.defineProperty(exports, "ValidationException", { enumerable: true, get: function () { return __importDefault(validation_exception_2).default; } });
var jwt_token_expired_exception_2 = require("./jwt-token-expired.exception");
Object.defineProperty(exports, "JWTTokenExpiredException", { enumerable: true, get: function () { return __importDefault(jwt_token_expired_exception_2).default; } });
var forbidden_exception_2 = require("./forbidden.exception");
Object.defineProperty(exports, "ForbiddenException", { enumerable: true, get: function () { return __importDefault(forbidden_exception_2).default; } });
var method_not_allowed_exception_2 = require("./method-not-allowed.exception");
Object.defineProperty(exports, "MethodNotAllowedException", { enumerable: true, get: function () { return __importDefault(method_not_allowed_exception_2).default; } });
var request_timeout_exception_2 = require("./request-timeout.exception");
Object.defineProperty(exports, "RequestTimeoutException", { enumerable: true, get: function () { return __importDefault(request_timeout_exception_2).default; } });
var too_many_requests_exception_2 = require("./too-many-requests.exception");
Object.defineProperty(exports, "TooManyRequestsException", { enumerable: true, get: function () { return __importDefault(too_many_requests_exception_2).default; } });
var not_implemented_exception_2 = require("./not-implemented.exception");
Object.defineProperty(exports, "NotImplementedException", { enumerable: true, get: function () { return __importDefault(not_implemented_exception_2).default; } });
var service_unavailable_exception_2 = require("./service-unavailable.exception");
Object.defineProperty(exports, "ServiceUnavailableException", { enumerable: true, get: function () { return __importDefault(service_unavailable_exception_2).default; } });
// Backward compatibility exports with @deprecated annotations
/**
* @deprecated Use BaseException instead
*/
var jsm_exception_exception_2 = require("./jsm-exception.exception");
Object.defineProperty(exports, "JsmException", { enumerable: true, get: function () { return __importDefault(jsm_exception_exception_2).default; } });
/**
* @deprecated Use InternalServerErrorException instead
*/
exports.InternalServerError = internal_server_error_exception_1.default;
/**
* @deprecated Use JWTTokenExpiredException instead
*/
exports.JWTTokenExpired = jwt_token_expired_exception_1.default;
/**
* @fileoverview JSM Exceptions Library - Comprehensive HTTP exception handling
* @author dr. Salmi <reevosolutions@gmail.com>
* @since 22-07-2025
*/
const exceptions = {
/**
* Base exception class that all JSM exceptions extend.
* Provides consistent error handling with HTTP status codes, context, and timestamps.
*/
BaseException: base_exception_1.default,
// 4xx Client Error Exceptions
/**
* HTTP 400 - Bad Request
* Thrown when the client sends a malformed or invalid request.
*/
BadRequestException: bad_request_exception_1.default,
/**
* HTTP 401 - Unauthorized
* Thrown when authentication is required but not provided or invalid.
*/
UnauthorizedException: unauthorized_error_exception_1.default,
/**
* HTTP 401 - Invalid Password
* Thrown when password authentication fails.
*/
InvalidPasswordException: invalid_password_exception_1.default,
/**
* HTTP 401 - JWT Token Expired
* Thrown when a JWT token has expired.
*/
JWTTokenExpiredException: jwt_token_expired_exception_1.default,
/**
* HTTP 403 - Forbidden
* Thrown when the client does not have permission to access a resource.
*/
ForbiddenException: forbidden_exception_1.default,
/**
* HTTP 404 - Item Not Found
* Thrown when a requested item/resource cannot be found.
*/
ItemNotFoundException: item_not_found_exception_1.default,
/**
* HTTP 404 - No Items Found
* Thrown when a search or list operation returns no results.
*/
NoItemsFoundException: no_items_found_exception_1.default,
/**
* Alias for NoItemsFoundException for backward compatibility
*/
NotFoundException: no_items_found_exception_1.default,
/**
* HTTP 405 - Method Not Allowed
* Thrown when the HTTP method is not allowed for the requested resource.
*/
MethodNotAllowedException: method_not_allowed_exception_1.default,
/**
* HTTP 408 - Request Timeout
* Thrown when a request times out.
*/
RequestTimeoutException: request_timeout_exception_1.default,
/**
* HTTP 409 - Conflict
* Thrown when attempting to create a resource that already exists.
*/
ValueAlreadyExistsException: value_already_exists_exception_1.default,
/**
* HTTP 422 - Unprocessable Entity
* Thrown when the request is well-formed but contains semantic errors.
*/
UnprocessableEntityException: unprocessable_entity_exception_1.default,
/**
* HTTP 422 - Validation Error
* Thrown when input validation fails. Supports Joi validation errors.
*/
ValidationException: validation_exception_1.default,
/**
* HTTP 429 - Too Many Requests
* Thrown when rate limiting is triggered.
*/
TooManyRequestsException: too_many_requests_exception_1.default,
// 5xx Server Error Exceptions
/**
* HTTP 500 - Internal Server Error
* Thrown when an unexpected server error occurs.
*/
InternalServerErrorException: internal_server_error_exception_1.default,
/**
* HTTP 501 - Not Implemented
* Thrown when a feature or functionality is not implemented.
*/
NotImplementedException: not_implemented_exception_1.default,
/**
* HTTP 503 - Service Unavailable
* Thrown when a service is temporarily unavailable.
*/
ServiceUnavailableException: service_unavailable_exception_1.default,
// 2xx Success "Exceptions" (special cases)
/**
* HTTP 204 - No Content
* Used when the request is valid but the server has nothing to send back.
* Used when an event is received and the service has nothing to do with it.
*/
NoContentException: no_content_exception_1.default,
// Backward Compatibility (Deprecated)
/**
* @deprecated Use BaseException instead
* Legacy JSM exception for backward compatibility.
*/
JsmException: jsm_exception_exception_1.default,
/**
* @deprecated Use InternalServerErrorException instead
* Legacy internal server error exception.
*/
InternalServerError: internal_server_error_exception_1.default,
/**
* @deprecated Use JWTTokenExpiredException instead
* Legacy JWT token expired exception.
*/
JWTTokenExpired: jwt_token_expired_exception_1.default,
};
exports.default = exceptions;