Return none as fallback Helicone (#228)

Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
This commit is contained in:
merwanehamadi
2023-07-31 20:18:15 -07:00
committed by GitHub
parent e0db4e9638
commit ce24857a74

View File

@@ -58,21 +58,21 @@ query ExampleQuery($properties: [PropertyFilter!]){
"operationName": operation_name,
},
)
response.raise_for_status() # Raises a HTTPError if the response was an unsuccessful status code
data = response.json()
except requests.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
raise # Re-raise the exception to stop execution
return None # Re-raise the exception to stop execution
except json.JSONDecodeError:
print(f"Invalid JSON response: {response.text if response else 'No response'}")
raise
return None
except Exception as err:
print(f"Other error occurred: {err}")
raise
return None
if data is None or data.get("data") is None:
raise ValueError("Invalid response received from server: no data")
print("Invalid response received from server: no data")
return None
return (
data.get("data", {}).get("aggregatedHeliconeRequest", {}).get("costUSD", None)