mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Removed HTMLErrorRenderer completely
refs:0799f02e80
refs:5e931e2e37
- with the referenced two commits I replaced our old HTML renderer with some code borrowed heavily from finalHandler - I had intended to modify this further to out put our message, context and help error messages - However, I ended up doing this in prepareError so it's done for all error renderers - There's now very little point keeping duplicated code from finalHandler just to output the status code - If we remove this code, express will fall back to finalHandler anyway, so the output is near identical
This commit is contained in:
parent
3b069b544f
commit
d7c4168452
1 changed files with 2 additions and 34 deletions
|
@ -256,34 +256,6 @@ const themeErrorRenderer = (err, req, res, next) => {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Borrowed heavily from finalHandler
|
||||
*/
|
||||
|
||||
const DOUBLE_SPACE_REGEXP = /\x20{2}/g;
|
||||
const NEWLINE_REGEXP = /\n/g;
|
||||
|
||||
function createHtmlDocument(status, message) {
|
||||
let body = escapeExpression(message)
|
||||
.replace(NEWLINE_REGEXP, '<br>')
|
||||
.replace(DOUBLE_SPACE_REGEXP, ' ');
|
||||
|
||||
return `<!DOCTYPE html>\n
|
||||
<html lang="en">\n
|
||||
<head>\n
|
||||
<meta charset="utf-8">\n
|
||||
<title>${status} Error</title>\n
|
||||
</head>\n
|
||||
<body>\n
|
||||
<pre>${status} ${body}</pre>\n
|
||||
</body>\n
|
||||
</html>\n`;
|
||||
}
|
||||
|
||||
const htmlErrorRenderer = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
||||
return res.send(createHtmlDocument(res.statusCode, err.stack));
|
||||
};
|
||||
|
||||
module.exports.resourceNotFound = (req, res, next) => {
|
||||
next(new errors.NotFoundError({message: tpl(messages.resourceNotFound)}));
|
||||
};
|
||||
|
@ -314,9 +286,7 @@ module.exports.handleHTMLResponse = [
|
|||
// Make sure the error can be served
|
||||
prepareError,
|
||||
// Handle the error in Sentry
|
||||
sentry.errorHandler,
|
||||
// Render the error using HTML format
|
||||
htmlErrorRenderer
|
||||
sentry.errorHandler
|
||||
];
|
||||
|
||||
module.exports.handleThemeResponse = [
|
||||
|
@ -325,7 +295,5 @@ module.exports.handleThemeResponse = [
|
|||
// Handle the error in Sentry
|
||||
sentry.errorHandler,
|
||||
// Render the error using theme template
|
||||
themeErrorRenderer,
|
||||
// Fall back to basic if HTML is not explicitly accepted
|
||||
htmlErrorRenderer
|
||||
themeErrorRenderer
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue