[feat] retry preload cards 3x

This commit is contained in:
2026-05-29 22:25:09 -04:00
parent e7c71e1c75
commit afae3f445e

View File

@@ -55,14 +55,32 @@ const syncProductLine = async (
"sort": {}, "sort": {},
}; };
const response = await fetch('https://mp-search-api.tcgplayer.com/v1/search/request?q=&isList=false', { let response: Response | null = null;
method: 'POST', let lastError: unknown = null;
headers: { 'Content-Type': 'application/json' }, for (let attempt = 1; attempt <= 3; attempt++) {
body: JSON.stringify(d), try {
}); const r = await fetch('https://mp-search-api.tcgplayer.com/v1/search/request?q=&isList=false', {
method: 'POST',
if (!response.ok) { headers: { 'Content-Type': 'application/json' },
throw new Error(`TCGPlayer search request failed: ${response.status} ${response.statusText}`); body: JSON.stringify(d),
});
if (r.ok) {
response = r;
break;
}
lastError = new Error(`TCGPlayer search request failed: ${r.status} ${r.statusText}`);
} catch (err) {
lastError = err;
}
if (attempt < 3) {
log(` retry ${attempt}/2 for search request in 5s...`);
await helper.Sleep(5000);
}
}
if (!response) {
throw lastError instanceof Error
? lastError
: new Error(`TCGPlayer search request failed: ${String(lastError)}`);
} }
const data = await response.json(); const data = await response.json();