Explorar o código

Add room_id param and content-type guard to Homestay calendar fetch

ZiB hai 4 meses
pai
achega
5919fdaae2
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      room_cal/service_api/_homestay.py

+ 8 - 1
room_cal/service_api/_homestay.py

@@ -65,11 +65,18 @@ class _HomestayClient:
 
   async def _fetch_calendar(self) -> dict:
     async with httpx.AsyncClient(follow_redirects=False) as client:
-      r = await client.get(f'{_BASE}/homestay_rooms/calendar', headers=self._headers())
+      r = await client.get(
+        f'{_BASE}/homestay_rooms/calendar',
+        params={'room_id': self._room_id},
+        headers=self._headers(),
+      )
     self._check_auth(r)
     if r.status_code >= 400:
       mark_stale('homestay')
       raise HomestayAuthError(f'Homestay calendar fetch failed (HTTP {r.status_code}) — run: {_AUTH_HINT}')
+    if 'application/json' not in r.headers.get('content-type', ''):
+      mark_stale('homestay')
+      raise HomestayAuthError(f'Homestay session expired — run: {_AUTH_HINT}')
     return r.json()
 
   async def _get_calendar_data(self) -> dict: