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}`); }