@@ -39,14 +39,25 @@ async def _make_api_request(
3939 auth : AuthContext , # auth is passed for context, actual token extraction TBD
4040 json_data : Optional [Dict [str , Any ]] = None ,
4141 params : Optional [Dict [str , Any ]] = None ,
42+ timeout : Optional [float ] = None ,
4243 ) -> Any :
4344 headers = {"Content-Type" : "application/json" , "Authorization" : f"Bearer { self .graph_api_key } " }
4445
4546 url = f"{ self .base_url .rstrip ('/' )} /{ endpoint .lstrip ('/' )} "
4647
47- async with httpx .AsyncClient () as client :
48+ # Set default timeout based on endpoint type
49+ if timeout is None :
50+ if "visualization" in endpoint :
51+ timeout = 1200.0 # 20 minutes for visualization requests
52+ else :
53+ timeout = 300.0 # 5 minutes for other requests
54+
55+ timeout_config = httpx .Timeout (timeout )
56+ async with httpx .AsyncClient (timeout = timeout_config ) as client :
4857 try :
49- logger .debug (f"Making API request: { method } { url } Data: { json_data } Params: { params } " )
58+ logger .debug (
59+ f"Making API request: { method } { url } Data: { json_data } Params: { params } Timeout: { timeout } s"
60+ )
5061 response = await client .request (method , url , json = json_data , headers = headers , params = params )
5162 response .raise_for_status () # Raise an exception for HTTP error codes (4xx or 5xx)
5263
@@ -419,6 +430,9 @@ async def get_graph_visualization_data(
419430
420431 request_data = {"graph_id" : graph_id }
421432 try :
433+ logger .info (
434+ f"Requesting visualization data for graph_id { graph_id } (may take up to 2 minutes for large graphs)"
435+ )
422436 api_response = await self ._make_api_request (
423437 method = "POST" ,
424438 endpoint = "/visualization" ,
@@ -468,6 +482,15 @@ async def get_graph_visualization_data(
468482
469483 except Exception as e :
470484 logger .error (f"Failed to call visualization API for graph_id { graph_id } : { e } " )
485+ # Check if this is a timeout error specifically
486+ if "timeout" in str (e ).lower () or "timed out" in str (e ).lower ():
487+ logger .warning (
488+ f"Visualization API timed out for graph_id { graph_id } . The graph may be large and still processing."
489+ )
490+ # For timeout errors, we could either:
491+ # 1. Return empty data with a warning (current behavior)
492+ # 2. Raise the exception to let the UI handle it
493+ # For now, keeping the existing behavior but adding better logging
471494 # Return empty visualization data on error
472495 return {"nodes" : [], "links" : []}
473496
0 commit comments