[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": {},
};
const response = await fetch('https://mp-search-api.tcgplayer.com/v1/search/request?q=&isList=false', {
let response: Response | null = null;
let lastError: unknown = null;
for (let attempt = 1; attempt <= 3; attempt++) {
try {
const r = await fetch('https://mp-search-api.tcgplayer.com/v1/search/request?q=&isList=false', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(d),
});
if (!response.ok) {
throw new Error(`TCGPlayer search request failed: ${response.status} ${response.statusText}`);
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();