UNPKG

@memory-bank/mcp

Version:

Memory-enabled Co-Pilot (MCP) server for managing project documentation and context

69 lines 2.05 kB
/** * Base error class for application * All custom errors should extend this class or its subclasses */ export class BaseError extends Error { code; details; /** * Error creation timestamp */ timestamp; /** * Original error that caused this error (if any) */ cause; /** * Create a new BaseError * * @param code Unique error code for identification and documentation * @param message Human-readable error message * @param details Additional error details for debugging and logging * @param options Additional error options */ constructor(code, message, details, options) { super(message, options); this.code = code; this.details = details; this.name = this.constructor.name; this.timestamp = new Date(); this.cause = options?.cause; if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } /** * Converts error to a plain object suitable for logging or serialization */ toJSON() { return { name: this.name, code: this.code, message: this.message, timestamp: this.timestamp.toISOString(), details: this.details, cause: this.cause ? { name: this.cause.name, message: this.cause.message, stack: this.cause.stack } : undefined, }; } /** * Get the HTTP status code corresponding to this error * Should be overridden by subclasses if needed */ getHttpStatusCode() { return 500; } /** * Returns true if the error is of the specified class * Safer than using instanceof when class definitions might be different * * @param errorClass Error class to check against */ isInstanceOf(errorClass) { return this.constructor.name === errorClass || this.name === errorClass; } } //# sourceMappingURL=BaseError.js.map