21 lines
540 B
TypeScript
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);
|
|
}
|
|
}
|