fix: improve error handling for project activation in existing context
dipi.evil committed
Dec 19, 2025 at 11:34 UTC
265e31e4bbb832f2b5b650906e0d88ff20e9c815
1 file changed
+2
-9
python/api/api_message.py
+2
-9
@@ -78,7 +78,7 @@ class ApiMessage(ApiHandler):
78
if context_id:
79
if agent_profile:
80
return Response('{"error": "Cannot override agent profile on existing context"}', status=400, mimetype="application/json")
81
- context = AgentContext.use(context_id)
81
+ context = AgentContext.use(context_id)
82
if not context:
83
return Response('{"error": "Context not found"}', status=404, mimetype="application/json")
84
else:
@@ -91,16 +91,9 @@ class ApiMessage(ApiHandler):
91
try:
92
activate_project(context_id, project_name)
93
except Exception as e:
94
- # Handle non-existent project or context errors more gracefully
94
+ # Handle project or context errors more gracefully
95
error_msg = str(e)
96
PrintStyle.error(f"Failed to activate project '{project_name}' for context '{context_id}': {error_msg}")
97
- # If the error message suggests a missing resource, return 404; otherwise, 500
98
- if "not found" in error_msg.lower() or "does not exist" in error_msg.lower():
99
- return Response(
100
- f'{{"error": "Project \\"{project_name}\\" not found"}}',
101
- status=404,
102
- mimetype="application/json",
103
- )
97
return Response(
98
f'{{"error": "Failed to activate project \\"{project_name}\\""}}',
99
status=500,