@etsoo/shared
Version:
TypeScript shared utilities and functions
26 lines (22 loc) • 547 B
text/typescript
/**
* Error with custom data
* Other information can be hold by 'name', 'cause', and 'stack' property
*
*/
export class DataError<T = Record<string, unknown>> extends Error {
/**
* Custom data
*/
public readonly data: T;
/**
* Constructor
* @param message Error message
* @param data Custom data
*/
constructor(message: string, data: T) {
super(message);
this.data = data;
// Set the prototype explicitly to ensure instanceof works correctly
Object.setPrototypeOf(this, DataError.prototype);
}
}