From 89b1d76c7ebaa109b11e9a555d9e920586002044 Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:25:03 -0500 Subject: [PATCH] Actions: Improve logging for smogon request failures --- src/actions.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/actions.ts b/src/actions.ts index 54e013f..3f52cfc 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -66,7 +66,8 @@ const redundantFetch = async (targetUrl: string, data: RequestInit, attempts = 0 try { await fetch(targetUrl, data); } catch (e: any) { - if (e.code === 400) return console.error('400 on Smogon request', e, data); + console.log('error in smogon fetch', e); + if (e.code === 400) return; return redundantFetch(targetUrl, data, attempts++); } }; @@ -88,8 +89,9 @@ export function checkSuspectVerified( let reqsMet = 0; let reqCount = 0; const userData: Partial<{elo: number, gxe: number, coil: number}> = {}; - for (const k in reqs) { - if (!reqs[k as 'elo' | 'coil' | 'gxe']) continue; + const reqKeys = ['elo', 'coil', 'gxe'] as const; + for (const k of reqKeys) { + if (!reqs[k]) continue; reqCount++; switch (k) { case 'coil': @@ -1098,13 +1100,13 @@ export const actions: {[k: string]: QueryHandler} = { if (this.getIp() !== Config.restartip) { throw new ActionError("Access denied."); } - const id = toID(params.format); + const id = toID(params.format || params.formatid); if (!id) throw new ActionError("No format ID specified."); const suspect = await tables.suspects.get(id); if (!suspect) throw new ActionError("There is no ongoing suspect for " + id); const userid = toID(params.userid); if (!userid || userid.length > 18) throw new ActionError("Invalid userid Pprovided."); - const rating = await tables.ladder.get(userid); + const rating = await new Ladder(id).getRating(userid); if (!rating) throw new ActionError("That user has no ratings in the given ladder."); return { result: checkSuspectVerified(rating, suspect, {elo: suspect.elo, coil: suspect.coil, gxe: suspect.gxe}),