Raise HTTP errors

This commit is contained in:
simonwt 2026-04-16 21:13:06 +01:00
parent cd1f0a2ae3
commit 7db5a29081

View file

@ -82,8 +82,11 @@ class APIClient(BaseModel):
# Make the API request and handle potential exceptions
try:
response = requests.request(method.upper(), url, json=data, headers=headers, timeout=20)
return_json = response.json()
with requests.Session() as session:
session.headers.update(headers)
response = session.request(method.upper(), url, json=data, headers=headers, timeout=20)
response.raise_for_status() # Raise an exception for HTTP errors
return_json = response.json()
except requests.exceptions.RequestException as e:
raise ConnectionError(f"An error occurred while making the request: {e}")
except json.JSONDecodeError as e: