UNPKG

@eventmsg/core

Version:

EventMsgV3 TypeScript library - Core protocol implementation with transport abstraction

62 lines (61 loc) 1.79 kB
//#region src/errors/event-msg-error.ts /** * Base error class for all EventMsg-related errors. * Provides consistent error handling with context and solutions. */ var EventMsgError = class extends Error { /** Error code for programmatic handling */ code; /** Additional context about the error */ context; /** Suggested solutions for the error */ solutions; /** Original error that caused this error */ cause; constructor(message, code, options = {}) { super(message); this.name = this.constructor.name; this.code = code; this.context = options.context; this.solutions = options.solutions || []; this.cause = options.cause; if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor); } /** * Get a detailed error message including context and solutions */ getDetailedMessage() { let details = `${this.name}: ${this.message}`; if (this.code) details += ` (${this.code})`; if (this.context && Object.keys(this.context).length > 0) { details += "\nContext:"; for (const [key, value] of Object.entries(this.context)) details += `\n ${key}: ${JSON.stringify(value)}`; } if (this.solutions.length > 0) { details += "\nSuggested solutions:"; for (const solution of this.solutions) details += `\n • ${solution}`; } if (this.cause) details += `\nCaused by: ${this.cause.message}`; return details; } /** * Convert error to JSON for logging/serialization */ toJSON() { return { name: this.name, message: this.message, code: this.code, context: this.context, solutions: this.solutions, stack: this.stack, cause: this.cause ? { name: this.cause.name, message: this.cause.message } : void 0 }; } }; //#endregion export { EventMsgError }; //# sourceMappingURL=event-msg-error.js.map