mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-19 15:00:09 +00:00
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.
This commit is contained in:
parent
d18317a7c8
commit
0c1dd73341
2 changed files with 8 additions and 0 deletions
|
@ -340,6 +340,7 @@ export class ApiCallService implements OnApplicationShutdown {
|
|||
code: 'RATE_LIMIT_EXCEEDED',
|
||||
id: 'd5826d14-3982-4d2e-8011-b9e9f02499ef',
|
||||
httpStatusCode: 429,
|
||||
info,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue