Skip to content

Commit

Permalink
Actions: Improve logging for smogon request failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 29, 2024
1 parent bf82e31 commit 89b1d76
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++);
}
};
Expand All @@ -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':
Expand Down Expand Up @@ -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}),
Expand Down

0 comments on commit 89b1d76

Please sign in to comment.