Skip to content

Commit

Permalink
feat: handle err.cause & err.stack
Browse files Browse the repository at this point in the history
This is a replacement for pillarjs#49.
I just pulled out the specific change related to this issue and added it here.

Closes: expressjs/express#5630
  • Loading branch information
coltonehrman committed Aug 11, 2024
1 parent 75c606a commit 25e187a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ function getErrorMessage (err, status, env) {
// use err.stack, which typically includes err.message
msg = err.stack

// fallback to err.toString() when possible
if (!msg && typeof err.toString === 'function') {
if (err && err.cause && err.cause.stack) {
msg += '\n[cause]: ' + err.cause.stack
} else if (err && err.stack) {
msg += '\n[stack]: ' + err.stack
} else if (!msg && typeof err.toString === 'function') {
// fallback to err.toString() when possible
msg = err.toString()
}
}
Expand Down

0 comments on commit 25e187a

Please sign in to comment.