tranxpress
Version:
A smart async wrapper for Express with MongoDB transaction support.
27 lines (22 loc) • 608 B
text/typescript
export class ErrorResponse extends Error {
statusCode: number;
details?: any;
constructor(message: string, statusCode: number = 500, details?: any) {
super(message);
this.statusCode = statusCode;
this.details = details;
// Maintains proper stack trace (only in V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = this.constructor.name;
}
toJSON() {
return {
status: false,
message: this.message,
statusCode: this.statusCode,
...(this.details && { details: this.details }),
};
}
}