diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f8a7d5..e1cfdc13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang +## [1.9.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.9.1) - 2025-04-04 + +### Changed + +- 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` + ## [1.10.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.10.0) - 2025-04-01 ### Deprecated diff --git a/infrahub_sdk/schema/__init__.py b/infrahub_sdk/schema/__init__.py index 080d7237..3a8773bb 100644 --- a/infrahub_sdk/schema/__init__.py +++ b/infrahub_sdk/schema/__init__.py @@ -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 @@ -13,6 +14,7 @@ from ..exceptions import ( InvalidResponseError, + JsonDecodeError, SchemaNotFoundError, ValidationError, ) @@ -420,7 +422,14 @@ async def _fetch( 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( + 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", []): diff --git a/pyproject.toml b/pyproject.toml index bc262f4f..f51be0a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [tool.poetry] name = "infrahub-sdk" -version = "1.10.0" +version = "1.10.1" description = "Python Client to interact with Infrahub" authors = ["OpsMill "] readme = "README.md" license = "Apache-2.0" homepage = "https://opsmill.com" -repository = "https://github.com/opsmill/infrahub" -documentation = "https://docs.infrahub.app/python-sdk/" +repository = "https://github.com/opsmill/infrahub-sdk-python" +documentation = "https://docs.infrahub.app/python-sdk/introduction" packages = [{ include = "infrahub_sdk" }] classifiers = [ "Intended Audience :: Developers",