Raise HTTP errors
This commit is contained in:
parent
cd1f0a2ae3
commit
7db5a29081
1 changed files with 5 additions and 2 deletions
|
|
@ -82,8 +82,11 @@ class APIClient(BaseModel):
|
||||||
|
|
||||||
# Make the API request and handle potential exceptions
|
# Make the API request and handle potential exceptions
|
||||||
try:
|
try:
|
||||||
response = requests.request(method.upper(), url, json=data, headers=headers, timeout=20)
|
with requests.Session() as session:
|
||||||
return_json = response.json()
|
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:
|
except requests.exceptions.RequestException as e:
|
||||||
raise ConnectionError(f"An error occurred while making the request: {e}")
|
raise ConnectionError(f"An error occurred while making the request: {e}")
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue