UNPKG

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.

55 lines (54 loc) 1.56 kB
/** * @fileoverview Base exception class for all JSM exceptions * @author dr. Salmi <reevosolutions@gmail.com> * @since 22-07-2025 */ /** * Base exception class that all JSM exceptions should extend. * Provides a consistent interface and behavior for all exceptions in the library. * * @class BaseException * @extends {Error} */ declare class BaseException extends Error { /** * HTTP status code associated with this exception * @type {number} * @default 500 */ readonly status: number; /** * Additional context or metadata about the exception * @type {Record<string, any>} */ readonly context?: Record<string, any>; /** * Timestamp when the exception was created * @type {Date} */ readonly timestamp: Date; /** * Creates an instance of BaseException. * * @param {string} [message='Internal server error'] - The error message * @param {number} [status=500] - HTTP status code * @param {Record<string, any>} [context] - Additional context * @memberof BaseException */ constructor(message?: string, status?: number, context?: Record<string, any>); /** * Returns a JSON representation of the exception * * @returns {object} JSON representation * @memberof BaseException */ toJSON(): object; /** * Returns a string representation of the exception * * @returns {string} String representation * @memberof BaseException */ toString(): string; } export default BaseException;