Mohamed Abu Basith commited on
Commit
b377aba
·
1 Parent(s): f305dcd

server chnages

Browse files
Files changed (1) hide show
  1. utils/AppError.js +9 -3
utils/AppError.js CHANGED
@@ -1,8 +1,14 @@
1
  class AppError extends Error {
2
- constructor(message, statuscode) {
3
  super(message);
4
- this.statuscode = statuscode;
 
 
 
 
 
 
5
  }
6
  }
7
 
8
- module.exports = { AppError };
 
1
  class AppError extends Error {
2
+ constructor(message, statusCode) {
3
  super(message);
4
+
5
+ this.statusCode = statusCode;
6
+ this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; // 'fail' for 4xx errors, 'error' for 5xx errors
7
+ this.isOperational = true; // Mark this error as operational (not a programming error)
8
+
9
+ // Capture the stack trace (excluding the constructor call)
10
+ Error.captureStackTrace(this, this.constructor);
11
  }
12
  }
13
 
14
+ module.exports = { AppError };