export async function runWithSessionRefresh( action: () => Promise, refreshSession: () => Promise ): Promise { 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 }