feat: refresh-token (#9286)

Co-authored-by: NFish <douxc512@gmail.com>
This commit is contained in:
Wu Tianwei
2024-10-12 23:40:38 +08:00
committed by GitHub
parent 70c5b23089
commit dbfbc56de7
8 changed files with 164 additions and 12 deletions

View File

@@ -39,3 +39,21 @@ export const getPurifyHref = (href: string) => {
return escape(href)
}
export async function fetchWithRetry<T = any>(fn: Promise<T>, retries = 3): Promise<[Error] | [null, T]> {
const [error, res] = await asyncRunSafe(fn)
if (error) {
if (retries > 0) {
const res = await fetchWithRetry(fn, retries - 1)
return res
}
else {
if (error instanceof Error)
return [error]
return [new Error('unknown error')]
}
}
else {
return [null, res]
}
}