File size: 488 Bytes
97f53b4
b377aba
97f53b4
b377aba
 
 
 
 
 
 
97f53b4
 
 
b377aba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 };