export abstract class BaseError extends Error {
public readonly code: string;
public readonly statusCode: number;
public readonly timestamp: Date;
constructor(message: string, code: string, statusCode: number = 500) {
super(message);
this.name = this.constructor.name;
this.code = code;
this.statusCode = statusCode;
this.timestamp = new Date();
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
public toJSON() {
return {
name: this.name,
message: this.message,
code: this.code,
statusCode: this.statusCode,
timestamp: this.timestamp,
stack: this.stack,
};
}
}