Slightly better error handling for non 200 status codes from Gateway. (#7038)

* Slightly better error handling for non 200 status codes from Gateway.

* Apply suggestion from @chrismeyersfsu

Co-authored-by: Chris Meyers <chrismeyersfsu@users.noreply.github.com>

---------

Co-authored-by: Chris Meyers <chrismeyersfsu@users.noreply.github.com>
This commit is contained in:
Andrew Potozniak 2025-08-01 14:30:30 -04:00 committed by thedoubl3j
parent d452098123
commit a0b6083d4e
No known key found for this signature in database
GPG Key ID: E84C42ACF75B0768

View File

@ -464,17 +464,18 @@ class GatewayClient:
# Return the specific setting value or None if not found
return settings_data.get(setting_name)
else:
error_msg = f"Failed to get Gateway settings. Status: {response.status_code}"
error_msg = f"Failed to get Gateway settings from '{endpoint}' for '{setting_name}'. Status: {response.status_code}"
error_data = response.text
try:
error_data = response.json()
error_msg += f", Error: {error_data}"
except requests.exceptions.JSONDecodeError:
error_msg += f", Response: {response.text}"
raise GatewayAPIError(error_msg, response.status_code, response.json() if response.content else None)
raise GatewayAPIError(error_msg, response.status_code, error_data)
except requests.RequestException as e:
raise GatewayAPIError(f"Failed to get Gateway setting: {str(e)}")
raise GatewayAPIError(f"Failed to get Gateway settings from '{endpoint}' for '{setting_name}'. Unexpected Exception - Error: {str(e)}")
def get_base_url(self) -> str:
"""Get the base URL of the Gateway instance.