|
|
@@ -151,6 +151,14 @@ def _page_view_id() -> str:
|
|
|
return ''.join(random.choices('0123456789abcdef', k=16))
|
|
|
|
|
|
|
|
|
+def _raise_gql_errors(raw: dict, op: str) -> None:
|
|
|
+ """Raise RuntimeError when a GraphQL response body carries top-level errors."""
|
|
|
+ if raw.get('errors'):
|
|
|
+ _log.warning('booking %s gql errors: %s', op, json.dumps(raw['errors']))
|
|
|
+ msgs = ', '.join(e.get('message', '') for e in raw['errors'])
|
|
|
+ raise RuntimeError(f'GraphQL error: {msgs}')
|
|
|
+
|
|
|
+
|
|
|
@register_service('booking')
|
|
|
class _BookingClient(ServiceClientBase):
|
|
|
service_name = 'Booking.com'
|
|
|
@@ -371,10 +379,7 @@ class _BookingClient(ServiceClientBase):
|
|
|
)
|
|
|
r = await self._request(_do_request, op=operation_name)
|
|
|
raw = r.json()
|
|
|
- if raw.get('errors'):
|
|
|
- _log.warning('booking _msg_gql %s gql errors: %s', operation_name, json.dumps(raw['errors']))
|
|
|
- msgs = ', '.join(e.get('message', '') for e in raw['errors'])
|
|
|
- raise RuntimeError(f'GraphQL error: {msgs}')
|
|
|
+ _raise_gql_errors(raw, operation_name)
|
|
|
return raw
|
|
|
|
|
|
async def _multipart_post(self, url: str, referer: str, body: dict, extra_headers: dict | None = None) -> dict:
|
|
|
@@ -400,9 +405,7 @@ class _BookingClient(ServiceClientBase):
|
|
|
)
|
|
|
r = await self._request(_attempt, op='updateRoomDateMutation')
|
|
|
raw = r.json()
|
|
|
- if raw.get('errors'):
|
|
|
- msgs = ', '.join(e.get('message', '') for e in raw['errors'])
|
|
|
- raise RuntimeError(f'GraphQL error: {msgs}')
|
|
|
+ _raise_gql_errors(raw, 'updateRoomDateMutation')
|
|
|
result = (raw.get('data', {}).get('partnerAvailabilityMutations', {})
|
|
|
.get('partnerAvailabilityUpdate', {}))
|
|
|
if not result.get('success'):
|