From c28366772d6bc2d37c6b0a6ff69c7941766c4178 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 17 Aug 2021 01:43:39 -0700 Subject: [PATCH] Polyfill Promise.any for Node v14 Oops, Promise.any was added in Node 15, but prod uses Node 14! Polyfill it! --- api/assetImage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/assetImage.js b/api/assetImage.js index c28400d..9557be9 100644 --- a/api/assetImage.js +++ b/api/assetImage.js @@ -145,6 +145,20 @@ function reject(res, message, status = 400) { return res.status(status).send(message); } +// Polyfill Promise.any for older Node: https://github.com/ungap/promise-any +Promise.any = + Promise.any || + function ($) { + return new Promise(function (D, E, A, L) { + A = []; + L = $.map(function ($, i) { + return Promise.resolve($).then(D, function (O) { + return ((A[i] = O), --L) || E({ errors: A }); + }); + }).length; + }); + }; + async function handleWithBeeline(req, res) { beeline.withTrace( { name: "api/assetImage", operation_name: "api/assetImage" },