diff --git a/src/middlewares/error.js b/src/middlewares/error.js index e71769e8..697cfef2 100644 --- a/src/middlewares/error.js +++ b/src/middlewares/error.js @@ -8,7 +8,7 @@ const errorConverter = (err, req, res, next) => { if (!(error instanceof AppError)) { const statusCode = error.statusCode || httpStatus.INTERNAL_SERVER_ERROR; const message = error.message || httpStatus[statusCode]; - error = new AppError(statusCode, message, false); + error = new AppError(statusCode, message, false, err.stack); } next(error); }; diff --git a/src/utils/AppError.js b/src/utils/AppError.js index 16396b44..f702d4e7 100644 --- a/src/utils/AppError.js +++ b/src/utils/AppError.js @@ -1,9 +1,13 @@ class AppError extends Error { - constructor(statusCode, message, isOperational = true) { + constructor(statusCode, message, isOperational = true, stack = '') { super(message); this.statusCode = statusCode; this.isOperational = isOperational; - Error.captureStackTrace(this, this.constructor); + if (stack) { + this.stack = stack; + } else { + Error.captureStackTrace(this, this.constructor); + } } }