mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
fix(page.note): throw (not return) on all attempts throttled
This commit is contained in:
parent
5e6c6fccc4
commit
e36ea27517
1 changed files with 12 additions and 3 deletions
|
@ -37,13 +37,15 @@ async function sleep(ms: number): Promise<void> {
|
|||
}
|
||||
|
||||
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T> {
|
||||
let lastResult: T;
|
||||
let lastOk: boolean;
|
||||
let lastResultOrError: T;
|
||||
for (let i = 0; i < retryCount; i++) {
|
||||
const [ok, resultOrError] = await f()
|
||||
.then(result => [true, result])
|
||||
.catch(err => [false, err]);
|
||||
|
||||
lastResult = resultOrError;
|
||||
lastOk = ok;
|
||||
lastResultOrError = resultOrError;
|
||||
|
||||
if (ok) {
|
||||
break;
|
||||
|
@ -55,9 +57,16 @@ async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T>
|
|||
continue;
|
||||
}
|
||||
|
||||
// Throw for non-throttling errors
|
||||
throw resultOrError;
|
||||
}
|
||||
return lastResult;
|
||||
|
||||
if (lastOk) {
|
||||
return lastResultOrError;
|
||||
} else {
|
||||
// Give up after getting throttled too many times
|
||||
throw lastResultOrError;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
|
Loading…
Add table
Reference in a new issue