Avoid saving product data if nothing was returned (#101)

* fix: Check if productData is set first

Throughout my testing and debugging, it was possible for productData to
be "undefined". To prevent errors, it's best to check for it's existence
first.

Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech>

* fix: avoid saving wishlist when there's no change

Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech>

---------

Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech>
This commit is contained in:
Frostyfrog 2023-11-25 19:37:15 -07:00 committed by GitHub
parent b3146d339f
commit d633e90874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -161,6 +161,8 @@ class Wishlist {
} }
const productData = await getProductData(item.url) const productData = await getProductData(item.url)
if (!productData) return; // short-circuit when there's no data
for (const key of ['name', 'price', 'image']) { for (const key of ['name', 'price', 'image']) {
if (productData[key]) item[key] = productData[key] if (productData[key]) item[key] = productData[key]
} }