Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(free): prevent server flooding after 5xx #135

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/free/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Storage {
public jwt: string | undefined;
constructor(
private readonly token: string,
private readonly rootUrl = 'https://grammy-free-session.deno.dev',
private readonly rootUrl = 'https://grammy-free-session.deno.dev/api',
) {}

async login() {
Expand Down Expand Up @@ -108,7 +108,12 @@ async function retryFetch(
res = await fetch(...args);
if (res.status >= 500) {
console.error(`${res.status} in free session service, retrying!`);
await sleep(3000);
Satont marked this conversation as resolved.
Show resolved Hide resolved
}
} while (res.status >= 500);
return res;
}
}

async function sleep(ms: number) {
await new Promise((r) => setTimeout(r, ms));
}