lexguard-backend / src /utils /ApiError.js
github-actions[bot]
Deploy to Hugging Face
b921752
Raw
History Blame Contribute Delete
557 Bytes
/**
* Standardized application error class.
* Always throw this instead of plain Error in route/service code
* so the global error handler can format responses correctly.
*/
class ApiError extends Error {
constructor(statusCode, message, errors = [], stack = '') {
super(message);
this.statusCode = statusCode;
this.message = message;
this.success = false;
this.errors = errors;
if (stack) {
this.stack = stack;
} else {
Error.captureStackTrace(this, this.constructor);
}
}
}
module.exports = ApiError;