UNPKG

trapx

Version:

A plug-and-play middleware for standardized error handling in TypeScript-based Express.js applications

28 lines (27 loc) 891 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseError = void 0; class BaseError extends Error { constructor(params) { super(params.message); this.name = this.constructor.name; this.statusCode = params.statusCode; const metadata = params.metadata || {}; this.code = metadata.code || 'INTERNAL_SERVER_ERROR'; this.details = metadata.details || {}; this.isOperational = metadata.isOperational ?? true; Error.captureStackTrace(this, this.constructor); } toJSON() { return { name: this.name, message: this.message, statusCode: this.statusCode, code: this.code, details: this.details, isOperational: this.isOperational, stack: this.stack }; } } exports.BaseError = BaseError;