Minify: Don't set cache headers if `statFile()` causes 500

pull/4765/head
Richard Hansen 2021-02-11 19:16:55 -05:00 committed by John McLear
parent 84190793dc
commit 3eefe71834
1 changed files with 6 additions and 4 deletions

View File

@ -146,6 +146,11 @@ const minify = (req, res) => {
const contentType = mime.lookup(filename); const contentType = mime.lookup(filename);
util.callbackify(statFile)(filename, 3, (error, [date, exists]) => { util.callbackify(statFile)(filename, 3, (error, [date, exists]) => {
if (error) {
res.writeHead(500, {});
res.end();
return;
}
if (date) { if (date) {
date = new Date(date); date = new Date(date);
date.setMilliseconds(0); date.setMilliseconds(0);
@ -158,10 +163,7 @@ const minify = (req, res) => {
} }
} }
if (error) { if (!exists) {
res.writeHead(500, {});
res.end();
} else if (!exists) {
res.writeHead(404, {}); res.writeHead(404, {});
res.end(); res.end();
} else if (new Date(req.headers['if-modified-since']) >= date) { } else if (new Date(req.headers['if-modified-since']) >= date) {