Skip to content

Commit

Permalink
Artemis: Stop throwing 429 errors
Browse files Browse the repository at this point in the history
We already throttle requests when we get 429s. We don't need to log it constantly too.
  • Loading branch information
mia-pi-git committed Dec 24, 2024
1 parent cf00709 commit 7e8b7a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/artemis/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let throttleTime: number | null = null;
export const limiter = new Limiter(800);
export const PM = new ProcessManager.QueryProcessManager<string, Record<string, number> | null>(module, async text => {
if (isCommon(text) || !limiter.shouldRequest()) return null;
if (throttleTime && (Date.now() - throttleTime < 10000)) {
if (throttleTime && ((Date.now() - throttleTime) < 10000)) {
return null;
}
if (throttleTime) throttleTime = null;
Expand Down Expand Up @@ -90,9 +90,9 @@ export const PM = new ProcessManager.QueryProcessManager<string, Record<string,
return result;
} catch (e: any) {
throttleTime = Date.now();
if (e.message.startsWith('Request timeout')) {
// just ignore this. error on their end not ours.
// todo maybe stop sending requests for a bit?
if (e.message.startsWith('Request timeout') || e.code === 429) {
// request timeout: just ignore this. error on their end not ours.
// 429: too many requests, we already freeze for 10s above so. not much more we can do
return null;
}
Monitor.crashlog(e, 'A Perspective API request', {request: JSON.stringify(requestData)});
Expand Down
2 changes: 2 additions & 0 deletions server/room-battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ export class RoomBattleTimer {
let didSomething = false;
for (const player of players) {
if (!player.id) continue; // already eliminated, relevant for FFA gamesif it
// https://play.pokemonshowdown.com/battle-gen9unratedrandombattle-2255606027-5a6bcd9zlb93e6id5pp7juvhcg5w41spw
// why is this line here?
if (player.turnSecondsLeft > 0) continue;
if (this.settings.timeoutAutoChoose && player.secondsLeft > 0 && player.knownActive) {
void this.battle.stream.write(`>${player.slot} default`);
Expand Down

0 comments on commit 7e8b7a0

Please sign in to comment.