mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added function names to mw-error-handler middleware
- this helps with debugging because all the middleware will now have function names, so it'll show up as something labeled vs `<anonymous>`
This commit is contained in:
parent
dd214aa67c
commit
319f251ad2
1 changed files with 9 additions and 9 deletions
|
@ -63,7 +63,7 @@ function isDependencyInStack(dependency, err) {
|
|||
/**
|
||||
* Get an error ready to be shown the the user
|
||||
*/
|
||||
module.exports.prepareError = (err, req, res, next) => {
|
||||
module.exports.prepareError = function prepareError(err, req, res, next) {
|
||||
debug(err);
|
||||
|
||||
if (Array.isArray(err)) {
|
||||
|
@ -97,7 +97,7 @@ module.exports.prepareError = (err, req, res, next) => {
|
|||
statusCode: err.statusCode,
|
||||
code: 'UNEXPECTED_ERROR'
|
||||
});
|
||||
// For everything else, create a generic 500 error, with context set to the original error message
|
||||
// For everything else, create a generic 500 error, with context set to the original error message
|
||||
} else {
|
||||
err = new errors.InternalServerError({
|
||||
err: err,
|
||||
|
@ -118,7 +118,7 @@ module.exports.prepareError = (err, req, res, next) => {
|
|||
next(err);
|
||||
};
|
||||
|
||||
module.exports.prepareStack = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
||||
module.exports.prepareStack = function prepareStack(err, req, res, next) { // eslint-disable-line no-unused-vars
|
||||
const clonedError = prepareStackForUser(err);
|
||||
|
||||
next(clonedError);
|
||||
|
@ -131,7 +131,7 @@ module.exports.prepareStack = (err, req, res, next) => { // eslint-disable-line
|
|||
* @param {import('express').Response} res
|
||||
* @param {import('express').NextFunction} next
|
||||
*/
|
||||
module.exports.jsonErrorRenderer = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
||||
module.exports.jsonErrorRenderer = function jsonErrorRenderer(err, req, res, next) { // eslint-disable-line no-unused-vars
|
||||
const userError = prepareUserMessage(err, req);
|
||||
|
||||
res.json({
|
||||
|
@ -153,8 +153,8 @@ module.exports.jsonErrorRenderer = (err, req, res, next) => { // eslint-disable-
|
|||
*
|
||||
* @param {String} [cacheControlHeaderValue] cache-control header value
|
||||
*/
|
||||
module.exports.prepareErrorCacheControl = (cacheControlHeaderValue) => {
|
||||
return (err, req, res, next) => {
|
||||
module.exports.prepareErrorCacheControl = function prepareErrorCacheControl(cacheControlHeaderValue) {
|
||||
return function prepareErrorCacheControlInner(err, req, res, next) {
|
||||
let cacheControl = cacheControlHeaderValue;
|
||||
if (!cacheControlHeaderValue) {
|
||||
// never cache errors unless it's a 404
|
||||
|
@ -174,7 +174,7 @@ module.exports.prepareErrorCacheControl = (cacheControlHeaderValue) => {
|
|||
};
|
||||
};
|
||||
|
||||
const prepareUserMessage = (err, req) => {
|
||||
const prepareUserMessage = function prepareUserMessage(err, req) {
|
||||
const userError = {
|
||||
message: err.message,
|
||||
context: err.context
|
||||
|
@ -224,7 +224,7 @@ const prepareUserMessage = (err, req) => {
|
|||
return userError;
|
||||
};
|
||||
|
||||
module.exports.resourceNotFound = (req, res, next) => {
|
||||
module.exports.resourceNotFound = function resourceNotFound(req, res, next) {
|
||||
if (req && req.headers && req.headers['accept-version']
|
||||
&& res.locals && res.locals.safeVersion
|
||||
&& semver.compare(semver.coerce(req.headers['accept-version']), semver.coerce(res.locals.safeVersion)) !== 0) {
|
||||
|
@ -266,7 +266,7 @@ module.exports.resourceNotFound = (req, res, next) => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports.pageNotFound = (req, res, next) => {
|
||||
module.exports.pageNotFound = function pageNotFound(req, res, next) {
|
||||
next(new errors.NotFoundError({message: tpl(messages.pageNotFound)}));
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue