From 25e187a021203ea0dfaf45ba65ad5d2a67312045 Mon Sep 17 00:00:00 2001 From: Colton Ehrman Date: Sat, 10 Aug 2024 19:06:50 -0500 Subject: [PATCH] feat: handle err.cause & err.stack This is a replacement for https://github.com/pillarjs/finalhandler/pull/49. I just pulled out the specific change related to this issue and added it here. Closes: https://github.com/expressjs/express/issues/5630 --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f628e42..26b1fba 100644 --- a/index.js +++ b/index.js @@ -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() } }