|
20 | 20 | import humps # type: ignore |
21 | 21 | from aiohttp import ClientConnectorError |
22 | 22 | from aiohttp import ClientOSError |
| 23 | +from aiohttp import ClientResponseError |
23 | 24 | from aiohttp import ServerDisconnectedError |
24 | 25 | from pydantic.dataclasses import dataclass |
25 | 26 | from tortoise import fields |
@@ -161,16 +162,21 @@ async def configure(self, force: bool = False) -> None: |
161 | 162 |
|
162 | 163 | async def _hasura_request(self, endpoint: str, json: Dict[str, Any]) -> Dict[str, Any]: |
163 | 164 | self._logger.debug('Sending `%s` request: %s', endpoint, dump_json(json)) |
164 | | - result = await self.request( |
165 | | - method='post', |
166 | | - cache=False, |
167 | | - url=f'{self._hasura_config.url}/v1/{endpoint}', |
168 | | - json=json, |
169 | | - headers=self._hasura_config.headers, |
170 | | - ) |
| 165 | + try: |
| 166 | + result = await self.request( |
| 167 | + method='post', |
| 168 | + cache=False, |
| 169 | + url=f'{self._hasura_config.url}/v1/{endpoint}', |
| 170 | + json=json, |
| 171 | + headers=self._hasura_config.headers, |
| 172 | + ) |
| 173 | + except ClientResponseError as e: |
| 174 | + raise HasuraError(f'{e.status} {e.message}') from e |
| 175 | + |
171 | 176 | self._logger.debug('Response: %s', result) |
172 | | - if 'error' in result or 'errors' in result: |
173 | | - raise HasuraError(result) |
| 177 | + if errors := result.get('error') or result.get('errors'): |
| 178 | + raise HasuraError(errors) |
| 179 | + |
174 | 180 | return result |
175 | 181 |
|
176 | 182 | async def _healthcheck(self) -> None: |
@@ -212,8 +218,11 @@ def _hash_metadata(self, metadata: Dict[str, Any]) -> str: |
212 | 218 | async def _replace_metadata(self, metadata: Dict[str, Any]) -> None: |
213 | 219 | self._logger.info('Replacing metadata') |
214 | 220 | endpoint, json = 'query', { |
215 | | - "type": "replace_metadata", |
216 | | - "args": metadata, |
| 221 | + 'type': 'replace_metadata', |
| 222 | + 'args': { |
| 223 | + 'metadata': metadata, |
| 224 | + 'allow_inconsistent_metadata': True, |
| 225 | + }, |
217 | 226 | } |
218 | 227 | await self._hasura_request(endpoint, json) |
219 | 228 |
|
|
0 commit comments