From 8f236b86877efd5db3ca289619baaa194c95048b Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 21 Apr 2021 16:29:55 -0400 Subject: [PATCH] Minify: Avoid crash due to unhandled Promise rejection if stat fails --- src/node/utils/Minify.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 39cb24c9f..83c4be550 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -89,7 +89,15 @@ const requestURI = async (url, method, headers) => { }; const requestURIs = (locations, method, headers, callback) => { - Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => { + Promise.all(locations.map(async (loc) => { + try { + return await requestURI(loc, method, headers); + } catch (err) { + logger.debug(`requestURI(${JSON.stringify(loc)}, ${JSON.stringify(method)}, ` + + `${JSON.stringify(headers)}) failed: ${err.stack || err}`); + return [500, headers, '']; + } + })).then((responses) => { const statuss = responses.map((x) => x[0]); const headerss = responses.map((x) => x[1]); const contentss = responses.map((x) => x[2]);