Files
xo-stack/packages/stack/src/utils/ext-error.ts
T

21 lines
540 B
TypeScript

export class ExtError extends Error {
constructor(
message: string,
public readonly details?: string,
) {
super(message);
// Capture the stack trace (V8 engines only)
// This step ensures the stack trace is captured correctly
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ExtError);
} else {
this.stack = new Error().stack;
console.error(this.stack);
}
// 👇️ because we are extending a built-in class
Object.setPrototypeOf(this, ExtError.prototype);
}
}