@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
55 lines (54 loc) • 1.81 kB
TypeScript
import { IncomingHeaders } from '../../requests/containers';
/**
* Options for constructing an Exception.
*/
interface IExceptionOptions {
/** Numeric status or error code (e.g., HTTP status). */
code: number;
/** Optional name of the exception. Defaults to class name if omitted. */
name?: string;
/**
* Optional message or array of message parts.
*/
message?: string[] | string;
/**
* Optional headers
*/
headers?: Record<string, any>;
}
/**
* Custom exception class extending the native Error.
* Includes an error code and supports construction from any Error instance.
*/
export default class Exception extends Error {
static name: string;
/**
* Numeric error code (e.g., HTTP status code between 100 and 599).
*/
code: number;
headers: IncomingHeaders;
/**
* Constructs a new Exception.
*
* @param options configuration for the exception including code, name, and message.
*/
constructor(options: IExceptionOptions);
/**
* Creates an Exception instance from any Error object.
* If the error is already an Exception, it is returned directly.
*
* @param error error to wrap or convert.
* @returns An Exception instance with code and message extracted.
*/
static fromError(error: Error): Exception;
/**
* Describe static exception class.
* Used for responses describing in the request meta.
*
* @param {string} description exception description, will override default description.
* @param {Record<string, string>} headers exception headers.
* @returns {Exception} exception with internal metadata definition.
*/
static describe(description: string, headers?: Record<string, string>): (new () => Exception);
}
export {};