fix: handle remote prices.tf error in background script

This commit is contained in:
2025-05-18 13:38:23 -04:00
parent fae3431556
commit 47523d5a6a

View File

@@ -78,6 +78,9 @@ async function priceUsingPricesTF(token: string, sku: string, retries: number =
throw new Error(`Cloudflare rate limit exceeded, stopping`) throw new Error(`Cloudflare rate limit exceeded, stopping`)
} }
} }
if (!response.ok) {
throw new Error(`Pricing request for ${sku} failed with status code: ${response.status}`);
}
const data = await response.json(); const data = await response.json();
const prices = new PricesResponse(); const prices = new PricesResponse();
prices.keys = data['sellKeys'] prices.keys = data['sellKeys']
@@ -100,7 +103,8 @@ chrome.runtime.onMessage.addListener(
priceUsingPricesTF(token, sku) priceUsingPricesTF(token, sku)
.then((response) => sendResponse(response)) .then((response) => sendResponse(response))
.catch(error => { .catch(error => {
sendResponse(error); console.error(`Received "${error}" error while pricing ${sku} using prices.tf`)
sendResponse(null);
return false; return false;
}) })
} }