Minify: Avoid crash due to unhandled Promise rejection if stat fails

pull/5015/head
Richard Hansen 2021-04-21 16:29:55 -04:00
parent e8df643d75
commit 8f236b8687
1 changed files with 9 additions and 1 deletions

View File

@ -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]);