Skip to content

Commit

Permalink
Fix issue in getProductById where product may be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
fdesjardins committed May 13, 2020
1 parent ef222bf commit 6fd0af0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}

0 comments on commit 6fd0af0

Please sign in to comment.