This commit is contained in:
viviannTam
2024-01-30 13:03:58 +08:00
parent f7e4775ed3
commit ac98abc23e
5 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,13 @@
class AppError extends Error {
constructor(msg, statusCode) {
super(msg);
this.statusCode = statusCode;
this.error = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
this.isOperational = true;
Error.captureStackTrace(this, this.constructor);
}
}
module.exports = AppError;

View File

View File

@ -0,0 +1,8 @@
//Checking that the request body is empty
exports.isEmpty = function (obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return JSON.stringify(obj) === JSON.stringify({});
}