Skip to content

Commit

Permalink
Fix error stack
Browse files Browse the repository at this point in the history
  • Loading branch information
hagopj13 committed Feb 16, 2020
1 parent ccc148e commit 48d1a5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/middlewares/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
8 changes: 6 additions & 2 deletions src/utils/AppError.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

Expand Down

0 comments on commit 48d1a5a

Please sign in to comment.