From 3c05a08482cbcff452ece8c11ff3a2a740c79503 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 15 Mar 2023 15:05:13 -0500 Subject: Logout bug hunt (#294) * Stop storing the log on disk * Add more info to the session logging * Only clear session tokens from storage when they've expired * Retry session resumption a few times if it's a network issue * Improvements to the 'connecting' screen --- src/lib/async/retry.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/lib/async/retry.ts (limited to 'src/lib/async') diff --git a/src/lib/async/retry.ts b/src/lib/async/retry.ts new file mode 100644 index 000000000..f14ae6cf6 --- /dev/null +++ b/src/lib/async/retry.ts @@ -0,0 +1,29 @@ +import {isNetworkError} from 'lib/strings/errors' + +export async function retry

( + retries: number, + cond: (err: any) => boolean, + fn: () => Promise

, +): Promise

{ + let lastErr + while (retries > 0) { + try { + return await fn() + } catch (e: any) { + lastErr = e + if (cond(e)) { + retries-- + continue + } + throw e + } + } + throw lastErr +} + +export async function networkRetry

( + retries: number, + fn: () => Promise

, +): Promise

{ + return retry(retries, isNetworkError, fn) +} -- cgit 1.4.1