From 57832d5e861600a71f9f7d6e67ea6d270165f26c Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 24 Aug 2026 22:28:13 +0200 Subject: [PATCH] Retry Beds24 data calls on 401 by invalidating the cached access token. When a data endpoint rejects the token with 401, the cached token is now cleared and one retry is attempted with a fresh token. This prevents a stale token from causing a cascade of 401s while still failing cleanly if refresh itself is rate-limited. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- src/lib/beds24.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/beds24.ts b/src/lib/beds24.ts index f0783fa..74b9e2c 100644 --- a/src/lib/beds24.ts +++ b/src/lib/beds24.ts @@ -119,7 +119,8 @@ async function beds24Get( houseId: string, path: string, searchParams: Record, - revalidateSeconds = 300 + revalidateSeconds = 300, + retryOnAuthFailure = true ): Promise { const token = await getAccessToken(houseId); @@ -137,6 +138,13 @@ async function beds24Get( next: { revalidate: revalidateSeconds }, }); + if (response.status === 401 && retryOnAuthFailure) { + // Access token may be stale/revoked. Clear it and retry once. + accessTokenCache.delete(houseId); + pendingTokenRequests.delete(houseId); + return beds24Get(houseId, path, searchParams, revalidateSeconds, false); + } + if (!response.ok) { throw new Error(`Beds24 API error: ${response.status} ${response.statusText}`); }