-
Notifications
You must be signed in to change notification settings - Fork 42
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
Forward errors along to error handling middlewares #11
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 |
---|---|---|
|
@@ -36,32 +36,32 @@ function fastbootExpressMiddleware(distPath, options) { | |
result.html() | ||
.then(html => { | ||
let headers = result.headers; | ||
let statusMessage = result.error ? 'NOT OK ' : 'OK '; | ||
|
||
for (var pair of headers.entries()) { | ||
res.set(pair[0], pair[1]); | ||
} | ||
|
||
log(result.statusCode, 'OK ' + path); | ||
if (result.error) { | ||
log("RESILIENT MODE CAUGHT:", result.error.stack); | ||
next(result.error); | ||
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.
|
||
} | ||
|
||
log(result.statusCode, statusMessage + path); | ||
res.status(result.statusCode); | ||
res.send(html); | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
res.sendStatus(500); | ||
res.status(500); | ||
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. Do we even need to do this? Or would the default handler do this? 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. We could eliminate logging for sure. 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. Seems better to let the user decide on logging; this would be annoying to disable if you didn't want it for some reason. 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. removed the |
||
next(error); | ||
}); | ||
} | ||
|
||
function failure(error) { | ||
if (error.name === "UnrecognizedURLError") { | ||
next(); | ||
} else { | ||
log(500, "Unknown Error: " + error.stack); | ||
if (error.stack) { | ||
res.status(500).send(error.stack); | ||
} else { | ||
res.sendStatus(500); | ||
} | ||
if (error.name !== "UnrecognizedURLError") { | ||
res.status(500); | ||
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. Do we even need to do this? Or would the default handler do this? 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. I think we should set If post-FastBoot middleware wants to change the status code and attempt recovery it can. But that doesn't change the fact that our middleware resulted in an internal server error (i.e., a 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. @arjansingh That rationale sounds reasonable to me. |
||
} | ||
next(error); | ||
} | ||
}; | ||
} | ||
|
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.
Readme update: if you are in resilient mode you delegate the error handling to us.