From 5fb3669d014ad8520220c80c23d11b59fde09c4e Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 21 Nov 2025 15:04:50 -0600 Subject: [PATCH] Website: Update error handler in http config (#36155) Closes: https://github.com/fleetdm/fleet/issues/36127 Changes: - Updated the middlewareErrorHandler in the website's http config to send 412 responses for `PreconditionFailedError` errors. --- website/config/http.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/website/config/http.js b/website/config/http.js index 37ebf74c92..d47702140c 100644 --- a/website/config/http.js +++ b/website/config/http.js @@ -71,11 +71,14 @@ 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. + // 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, or sends a request with an invalid 'If-Match' header value. 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(); + // If this is a 'PreconditionFailedError' error, respond with a 412 status code. + } else if(err.message === 'Precondition Failed') { + return res.status(412).send(); } else { return next(err); }