In a function I have I try to take a value, and if the value ends up as undefined
, then I call the same function but with a different parameter
let price = await getPrice(name, category, '1');
if (price === undefined) {
price = await getPrice(name, category, '2');
if (price === undefined) {
price = await getPrice(name, category, '3');
}
}
I’m told that this approach can be very error prone, and after a bit of analyzing, I can see why. However, I don’t know if there’s a better way to handle this.
I need the third parameter since I use it to process a URL, as that URL has one of those strings.
static getPrice(productName, productCategory, variantNumber) {
...
let url = `https://exampleurl.com/${productName}cat=${productCategory}${variantNumber}`;
...
}