Skip to content

Commit 13381aa

Browse files
authored
Update error message for missing logs list (#126)
1 parent 585435e commit 13381aa

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

quotientai/resources/logs.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,33 @@ def list(
255255

256256
try:
257257
response = self._client._get("/logs", params=params)
258+
if response is None:
259+
logger.error(
260+
f"Failed to retrieve logs from API. The server returned no response. Please check your connection and try again."
261+
)
262+
return []
263+
264+
if response.get("logs") is None:
265+
time_range = ""
266+
if start_date and end_date:
267+
time_range = f" from {start_date.strftime('%Y-%m-%d')} to {end_date.strftime('%Y-%m-%d')}"
268+
elif start_date:
269+
time_range = f" from {start_date.strftime('%Y-%m-%d')} onwards"
270+
elif end_date:
271+
time_range = f" until {end_date.strftime('%Y-%m-%d')}"
272+
273+
filters = []
274+
if app_name:
275+
filters.append(f"app_name '{app_name}'")
276+
if environment:
277+
filters.append(f"environment '{environment}'")
278+
279+
filter_text = f" for {', '.join(filters)}" if filters else ""
280+
logger.error(
281+
f"No logs found{filter_text}{time_range}. Please check your query parameters or try again in 30 seconds."
282+
)
283+
return []
284+
258285
data = response["logs"]
259286

260287
logs = []
@@ -422,11 +449,33 @@ async def list(
422449

423450
try:
424451
response = await self._client._get("/logs", params=params)
425-
if response is None or response["logs"] is None:
452+
if response is None:
426453
logger.error(
427-
f"No logs found. Please check your query parameters and try again."
454+
f"Failed to retrieve logs from API. The server returned no response. Please check your connection and try again."
428455
)
429456
return []
457+
458+
if response.get("logs") is None:
459+
time_range = ""
460+
if start_date and end_date:
461+
time_range = f" from {start_date.strftime('%Y-%m-%d')} to {end_date.strftime('%Y-%m-%d')}"
462+
elif start_date:
463+
time_range = f" from {start_date.strftime('%Y-%m-%d')} onwards"
464+
elif end_date:
465+
time_range = f" until {end_date.strftime('%Y-%m-%d')}"
466+
467+
filters = []
468+
if app_name:
469+
filters.append(f"app_name '{app_name}'")
470+
if environment:
471+
filters.append(f"environment '{environment}'")
472+
473+
filter_text = f" for {', '.join(filters)}" if filters else ""
474+
logger.error(
475+
f"No logs found{filter_text}{time_range}. Please check your query parameters or try again in 30 seconds."
476+
)
477+
return []
478+
430479
data = response["logs"]
431480

432481
logs = []

0 commit comments

Comments
 (0)