19 lines
387 B
TypeScript
19 lines
387 B
TypeScript
export async function runWithSessionRefresh<T>(
|
|
action: () => Promise<T>,
|
|
refreshSession: () => Promise<void>
|
|
): Promise<T> {
|
|
let result: T
|
|
try {
|
|
result = await action()
|
|
} catch (error) {
|
|
try {
|
|
await refreshSession()
|
|
} catch {
|
|
// Preserve the actionable API error and its request ID.
|
|
}
|
|
throw error
|
|
}
|
|
await refreshSession()
|
|
return result
|
|
}
|