hayat / utils /AppError.js
Mohamed Abu Basith
server chnages
b377aba
raw
history blame contribute delete
488 Bytes
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 };