You've already forked pages
forked from didirus/AstralRinth
* feat: api-client module for content v0 * feat: delete unused components + modules + setting * feat: xhr uploading * feat: fs module -> api-client * feat: migrate files.vue to use tanstack * fix: mem leak + other issues * fix: build * feat: switch to monaco * fix: go back to using ace, but improve preloading + theme * fix: styling + dead attrs * feat: match figma * fix: padding * feat: files-new for ui page structure * feat: finalize files.vue * fix: lint * fix: qa * fix: dep * fix: lint * fix: lockfile merge * feat: icons on navtab * fix: surface alternating on table * fix: hover surface color --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
21 lines
449 B
TypeScript
21 lines
449 B
TypeScript
import { ModrinthApiError } from '../core/errors'
|
|
|
|
/**
|
|
* Wrap a function with JWT retry logic.
|
|
* On 401, calls refreshToken() and retries once.
|
|
*/
|
|
export async function withJWTRetry<T>(
|
|
fn: () => Promise<T>,
|
|
refreshToken: () => Promise<void>,
|
|
): Promise<T> {
|
|
try {
|
|
return await fn()
|
|
} catch (error) {
|
|
if (error instanceof ModrinthApiError && error.statusCode === 401) {
|
|
await refreshToken()
|
|
return await fn()
|
|
}
|
|
throw error
|
|
}
|
|
}
|