Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Member

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?

typeof setImmediate === 'function'
? setImmediate
: function (fn) {
process.nextTick(fn.bind.apply(fn, arguments))
}
var isFinished = onFinished.isFinished

/**
Expand All @@ -41,20 +44,22 @@ var isFinished = onFinished.isFinished
*/

function createHtmlDocument (message) {
var body = escapeHtml(message)
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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, ' &nbsp;')
var body = escapeHtml(message).replace(NEWLINE_REGEXP, '<br>').replace(DOUBLE_SPACE_REGEXP, ' &nbsp;')

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'
)
}

/**
Expand Down Expand Up @@ -175,6 +180,13 @@ function getErrorMessage (err, status, env) {
// use err.stack, which typically includes err.message
msg = err.stack

// if error cause included
Copy link
Member

Choose a reason for hiding this comment

The 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()
Expand Down Expand Up @@ -253,9 +265,7 @@ function getResponseStatusCode (res) {
*/

function headersSent (res) {
return typeof res.headersSent !== 'boolean'
Copy link
Member

Choose a reason for hiding this comment

The 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
}

/**
Expand Down
Loading