From 597007f588c10f1a1a7c77e89ae83611eb07c658 Mon Sep 17 00:00:00 2001 From: pbrassel <52356233+pbrassel@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:17:16 +0200 Subject: [PATCH] fix: error response model Make the error response model less strict because the structure of the payload for error responses varies. --- flame_hub/_exceptions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/flame_hub/_exceptions.py b/flame_hub/_exceptions.py index 95f101f..c5855f9 100644 --- a/flame_hub/_exceptions.py +++ b/flame_hub/_exceptions.py @@ -1,17 +1,15 @@ from json import JSONDecodeError import httpx2 as httpx -from pydantic import ValidationError, BaseModel, ConfigDict +from pydantic import ValidationError, BaseModel, ConfigDict, Field, AliasChoices class ErrorResponse(BaseModel): model_config = ConfigDict(extra="allow") """Configuration so that extra properties may be available.""" - name: str - """Name of the error.""" code: str """Name of the error code.""" - status_code: int + status_code: int | None = Field(validation_alias=AliasChoices("status_code", "statusCode"), default=None) """HTTP code of the response.""" message: str """The error message.""" @@ -67,7 +65,10 @@ def new_hub_api_error_from_response(r: httpx.Response) -> HubAPIError: error_message = f"received status code {r.status_code}" try: - error_response = ErrorResponse(**({"status_code": r.status_code} | r.json())) + error_response = ErrorResponse(**r.json()) + # Sometimes the status code is not part of the payload. + if error_response.status_code is None: + error_response.status_code = r.status_code error_message = f"received status code {error_response.status_code} ({error_response.code}): " if error_response.message.strip() == "":