Time out manifest requests after 2sec

We do a thing where we sometimes proactively update an appearance layer's manifest from images.neopets.com when it's been a while since the last time, _during_ user requests.

But when images.neopets.com is being slow, this makes our API requests about appearances super slow, too!

In this change, we add a 2-second timeout to those requests. That should be plenty for when images.neopets.com is in a good mood, but also give up fast enough for the site to not feel miserable lol :p (especially when the use "Use DTI's image archive" option is on!)
This commit is contained in:
Emi Matchu 2022-10-13 17:00:21 -07:00
parent 4619e86ae0
commit 8b3c256a5c

View file

@ -585,7 +585,12 @@ async function loadAndCacheAssetDataFromManifest(db, layer) {
async function loadAndCacheAssetManifest(db, layer) { async function loadAndCacheAssetManifest(db, layer) {
let manifest; let manifest;
try { try {
manifest = await loadAssetManifest(layer.url); manifest = await Promise.race([
loadAssetManifest(layer.url),
new Promise((_, reject) =>
setTimeout(() => reject(new Error(`manifest request timed out`)), 2000)
),
]);
} catch (e) { } catch (e) {
console.error( console.error(
new Error("Error loading asset manifest, caused by the error below") new Error("Error loading asset manifest, caused by the error below")