diff --git a/src/actions.ts b/src/actions.ts index 5dce223..722d5bb 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -66,6 +66,15 @@ if (Config.coilpath) { watchFile(Config.coilpath, () => Object.assign(coil, loadData(Config.coilpath))); } +const redundantFetch = async (url: string, data: RequestInit, attempts = 0): Promise => { + if (attempts >= 10) return; + try { + await fetch(url, data); + } catch (e: any) { + if (e.code === 400) return console.error('400 on Smogon request', e, data); + return redundantFetch(url, data, attempts++); + } +} export const actions: {[k: string]: QueryHandler} = { async register(params) { @@ -397,14 +406,12 @@ export const actions: {[k: string]: QueryHandler} = { reqs: {required: reqs, actual: userData}, suspectStartDate: suspects[formatid].startDate, }); - void fetch("https://www.smogon.com/tools/api/suspect-verify", { + void redundantFetch("https://www.smogon.com/tools/api/suspect-verify", { method: 'POST', body: new URLSearchParams({ data, hash: await signAsync("RSA-SHA1", data, Config.privatekey), }), - }).catch(e => { - console.error("Smogon request failed", e, {data, params}); }); } }