Skip to content

Commit 37d0d00

Browse files
authored
Merge pull request #343 from opsmill/dga-20250404-fix-http
Improve error message when a schema is not JSON valid.
2 parents bc3e1c8 + 4b0244c commit 37d0d00

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

changelog/+jsondecode.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve error message when a schema received from the server is not JSON valid. The new exception will be of type `infrahub_sdk.exceptions.JsonDecodeError` instead of `json.decoder.JSONDecodeError`

infrahub_sdk/schema/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import json
45
from collections.abc import MutableMapping
56
from enum import Enum
67
from time import sleep
@@ -13,6 +14,7 @@
1314

1415
from ..exceptions import (
1516
InvalidResponseError,
17+
JsonDecodeError,
1618
SchemaNotFoundError,
1719
ValidationError,
1820
)
@@ -420,7 +422,14 @@ async def _fetch(
420422
response = await self.client._get(url=url, timeout=timeout)
421423
response.raise_for_status()
422424

423-
data: MutableMapping[str, Any] = response.json()
425+
try:
426+
data: MutableMapping[str, Any] = response.json()
427+
except json.decoder.JSONDecodeError as exc:
428+
raise JsonDecodeError(
429+
message=f"Invalid Schema response received from the server at {response.url}: {response.text} [{response.status_code}] ",
430+
content=response.text,
431+
url=response.url,
432+
) from exc
424433

425434
nodes: MutableMapping[str, MainSchemaTypesAPI] = {}
426435
for node_schema in data.get("nodes", []):

0 commit comments

Comments
 (0)