-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Error cause
is not displayed
#49
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,12 @@ var DOUBLE_SPACE_REGEXP = /\x20{2}/g | |
var NEWLINE_REGEXP = /\n/g | ||
|
||
/* istanbul ignore next */ | ||
var defer = typeof setImmediate === 'function' | ||
? setImmediate | ||
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } | ||
var defer = | ||
typeof setImmediate === 'function' | ||
? setImmediate | ||
: function (fn) { | ||
process.nextTick(fn.bind.apply(fn, arguments)) | ||
} | ||
var isFinished = onFinished.isFinished | ||
|
||
/** | ||
|
@@ -41,20 +44,22 @@ var isFinished = onFinished.isFinished | |
*/ | ||
|
||
function createHtmlDocument (message) { | ||
var body = escapeHtml(message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requesting help to understand, do we really need change this? Perhaps it is already handling multiple line error message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also just to chime in, this kind of thing is exactly why (as requested in @IamLizu's other comment) we try to avoid unnecessary formatting changes. It makes it harder to figure out what is a functional change needing attention and what is purely presentation and can be ignored. |
||
.replace(NEWLINE_REGEXP, '<br>') | ||
.replace(DOUBLE_SPACE_REGEXP, ' ') | ||
var body = escapeHtml(message).replace(NEWLINE_REGEXP, '<br>').replace(DOUBLE_SPACE_REGEXP, ' ') | ||
|
||
return '<!DOCTYPE html>\n' + | ||
return ( | ||
'<!DOCTYPE html>\n' + | ||
'<html lang="en">\n' + | ||
'<head>\n' + | ||
'<meta charset="utf-8">\n' + | ||
'<title>Error</title>\n' + | ||
'</head>\n' + | ||
'<body>\n' + | ||
'<pre>' + body + '</pre>\n' + | ||
'<pre>' + | ||
body + | ||
'</pre>\n' + | ||
'</body>\n' + | ||
'</html>\n' | ||
) | ||
} | ||
|
||
/** | ||
|
@@ -175,6 +180,13 @@ function getErrorMessage (err, status, env) { | |
// use err.stack, which typically includes err.message | ||
msg = err.stack | ||
|
||
// if error cause included | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it handle nested cause? What if the cause itself has another cause? Also, perhaps it should append the stack trace of the error itself, regardless of whether the cause exists or not? |
||
if (err && err.cause && err.cause.stack) { | ||
msg += '\n[cause]: ' + err.cause.stack | ||
} else if (err && err.stack) { | ||
msg += '\n[stack]: ' + err.stack | ||
} | ||
|
||
// fallback to err.toString() when possible | ||
if (!msg && typeof err.toString === 'function') { | ||
msg = err.toString() | ||
|
@@ -253,9 +265,7 @@ function getResponseStatusCode (res) { | |
*/ | ||
|
||
function headersSent (res) { | ||
return typeof res.headersSent !== 'boolean' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert it, let's try to make less unwanted changes so its easier for the folks to review |
||
? Boolean(res._header) | ||
: res.headersSent | ||
return typeof res.headersSent !== 'boolean' ? Boolean(res._header) : res.headersSent | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please revert the formatting change?