mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Website: Add error handler middleware function to http config. (#19703)
Closes: #19679 Changes: - Added a custom error handler to the HTTP middleware that returns a 416: Range Not Satisfiable if the serve-static middleware throws a 'Range Not Satisfiable' error.
This commit is contained in:
parent
48ea95385e
commit
52ff031e98
1 changed files with 21 additions and 10 deletions
31
website/config/http.js
vendored
31
website/config/http.js
vendored
|
|
@ -29,16 +29,17 @@ module.exports.http = {
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// order: [
|
||||
// 'cookieParser',
|
||||
// 'session',
|
||||
// 'bodyParser',
|
||||
// 'compress',
|
||||
// 'poweredBy',
|
||||
// 'router',
|
||||
// 'www',
|
||||
// 'favicon',
|
||||
// ],
|
||||
order: [
|
||||
'cookieParser',
|
||||
'session',
|
||||
'bodyParser',
|
||||
'compress',
|
||||
'poweredBy',
|
||||
'router',
|
||||
'www',
|
||||
'favicon',
|
||||
'middlewareErrorHandler'
|
||||
],
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
|
|
@ -67,6 +68,16 @@ module.exports.http = {
|
|||
return middlewareFn;
|
||||
})(),
|
||||
|
||||
// Note: this middleware function will run for every HTTP request, but will only handle errors thrown by the serve-static middleware if a user requests an invalid byte range of a static asset.
|
||||
middlewareErrorHandler: function(err, req, res, next) {
|
||||
// If this is a 'RangeNotSatisfiableError' error, respond with a 416 status code.
|
||||
if (err.message === 'Range Not Satisfiable') {
|
||||
return res.status(416).send();
|
||||
} else {
|
||||
return next(err);
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue