Spaces:
Sleeping
Sleeping
class AppError extends Error { | |
constructor(message, statusCode) { | |
super(message); | |
this.statusCode = statusCode; | |
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; // 'fail' for 4xx errors, 'error' for 5xx errors | |
this.isOperational = true; // Mark this error as operational (not a programming error) | |
// Capture the stack trace (excluding the constructor call) | |
Error.captureStackTrace(this, this.constructor); | |
} | |
} | |
module.exports = { AppError }; |