From 6fd0af0dc6abc085c6d5ccf5ed2eb92eb939b549 Mon Sep 17 00:00:00 2001 From: Forrest Desjardins Date: Wed, 13 May 2020 15:53:45 -0400 Subject: [PATCH] Fix issue in getProductById where product may be undefined --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ce65850..a80a6d3 100644 --- a/index.js +++ b/index.js @@ -203,6 +203,10 @@ const buildUtcTime = (baseDateString, utcTimeString, advanceDate = false) => { const getProductById = async id => { const product = await fetch(`/products/${id}`) + if (product === undefined) { + return null + } + const parsedProductText = parseProductText(product.productText) parsedProductText.header.dataBasedOn = buildUtcTime( @@ -274,5 +278,7 @@ exports.FD1 = async ({ return true }) - return Promise.all(products.map(product => getProductById(product.id))) + const results = await Promise.all(products.map(product => getProductById(product.id))) + + return results.filter(result => result !== null) }