Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+jsondecode.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +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`
11 changes: 10 additions & 1 deletion infrahub_sdk/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import json
from collections.abc import MutableMapping
from enum import Enum
from time import sleep
Expand All @@ -13,6 +14,7 @@

from ..exceptions import (
InvalidResponseError,
JsonDecodeError,
SchemaNotFoundError,
ValidationError,
)
Expand Down Expand Up @@ -420,7 +422,14 @@
response = await self.client._get(url=url, timeout=timeout)
response.raise_for_status()

data: MutableMapping[str, Any] = response.json()
try:
data: MutableMapping[str, Any] = response.json()
except json.decoder.JSONDecodeError as exc:
raise JsonDecodeError(

Check warning on line 428 in infrahub_sdk/schema/__init__.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema/__init__.py#L427-L428

Added lines #L427 - L428 were not covered by tests
message=f"Invalid Schema response received from the server at {response.url}: {response.text} [{response.status_code}] ",
content=response.text,
url=response.url,
) from exc

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