Эх сурвалжийг харах

Raise on GraphQL errors from Airbnb set_availability mutation

Previously the response body was discarded, so content-level errors
(wrong variables, permissions, etc.) were silently swallowed.
ZiB 4 сар өмнө
parent
commit
9056ea0db7

+ 4 - 1
room_cal/service_api/_airbnb.py

@@ -356,7 +356,7 @@ class _AirbnbClient:
       raise AirbnbAuthError(f'Airbnb credentials are stale — run: {_AUTH_HINT}')
       raise AirbnbAuthError(f'Airbnb credentials are stale — run: {_AUTH_HINT}')
     if (cached := self._cache.get(d)) and cached.available == available:
     if (cached := self._cache.get(d)) and cached.available == available:
       return
       return
-    await self._mutate(
+    body = await self._mutate(
       'EditPanelAvailabilityMutation', _HASHES['EditPanelAvailabilityMutation'],
       'EditPanelAvailabilityMutation', _HASHES['EditPanelAvailabilityMutation'],
       {'input': {
       {'input': {
         'listingId': self._listing_id,
         'listingId': self._listing_id,
@@ -365,6 +365,9 @@ class _AirbnbClient:
       }, 'blockNotesEnabled': True},
       }, 'blockNotesEnabled': True},
       f'https://www.airbnb.com/multicalendar/{self._listing_id}/edit-selected-dates/{d}/{d}',
       f'https://www.airbnb.com/multicalendar/{self._listing_id}/edit-selected-dates/{d}/{d}',
     )
     )
+    if errors := body.get('errors'):
+      _log.error('airbnb set_availability date=%s errors=%s', d, errors)
+      raise AirbnbAuthError(f'Airbnb set_availability failed for {d}: {errors[0].get("message", errors)}')
     self.clear_cache()
     self.clear_cache()
     _log.info('airbnb set_availability date=%s available=%s', d, available)
     _log.info('airbnb set_availability date=%s available=%s', d, available)