diff --git a/src/trustcafeapiwrapper/apiclient.py b/src/trustcafeapiwrapper/apiclient.py index ef6b664..b622055 100644 --- a/src/trustcafeapiwrapper/apiclient.py +++ b/src/trustcafeapiwrapper/apiclient.py @@ -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: