diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-12-13 15:56:07 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-12-13 16:18:10 +0000 |
| commit | 0c1dd73341bdbdb05dfea0b6215fa4e0c3cd7a8b (patch) | |
| tree | bd27c3026fea1ac8f0855cd90f32b5c9ef464bcd /packages | |
| parent | merge: Add "enable RSS" user privacy toggle (resolves #826) (!806) (diff) | |
| download | sharkey-0c1dd73341bdbdb05dfea0b6215fa4e0c3cd7a8b.tar.gz sharkey-0c1dd73341bdbdb05dfea0b6215fa4e0c3cd7a8b.tar.bz2 sharkey-0c1dd73341bdbdb05dfea0b6215fa4e0c3cd7a8b.zip | |
on 429, retry `fetchAccount` instead of failing
when switching between accounts, with many tabs open (10 seem to be
enough), they all hit the endpoint at the same time, and some get rate
limited.
treating a 429 as a fatal error confuses the frontend, which ends up
logging the user out of all their accounts.
this code makes the frontend retry, after waiting the appropriate
amount of time.
seems to work fine in my testing.
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/backend/src/server/api/ApiCallService.ts | 1 | ||||
| -rw-r--r-- | packages/frontend/src/account.ts | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts index c6c33f7303..974be7e4e1 100644 --- a/packages/backend/src/server/api/ApiCallService.ts +++ b/packages/backend/src/server/api/ApiCallService.ts @@ -340,6 +340,7 @@ export class ApiCallService implements OnApplicationShutdown { code: 'RATE_LIMIT_EXCEEDED', id: 'd5826d14-3982-4d2e-8011-b9e9f02499ef', httpStatusCode: 429, + info, }); } } diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index e3416f2c29..f0a464084f 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -147,6 +147,13 @@ function fetchAccount(token: string, id?: string, forceShowDialog?: boolean): Pr text: i18n.ts.tokenRevokedDescription, }); } + } else if (res.error.id === 'd5826d14-3982-4d2e-8011-b9e9f02499ef') { + // rate limited + const timeToWait = res.error.info?.resetMs ?? 1000; + window.setTimeout(timeToWait, () => { + fetchAccount(token, id, forceShowDialog).then(done, fail); + }); + return; } else { await alert({ type: 'error', |