Skip to content

Commit 7e9a587

Browse files
committed
Enhance error handling in compile_and_fix function to manage HTTP errors gracefully
1 parent bb1ffab commit 7e9a587

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/mcp_tools.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ async def generate(description: str, requirements: str) -> str:
2828
async def compile_and_fix(code: str, description: str = "A Rust project", max_attempts: int = 3) -> str:
2929
"""Compile a Rust cargo project and fix any compiler errors"""
3030

31-
async with httpx.AsyncClient() as client:
32-
response = await client.post(f"{API_BASE_URL}/compile-and-fix",
33-
json={'code': code, 'description': description, 'max_attempts': max_attempts})
34-
return response.text
31+
async with httpx.AsyncClient(timeout=60.0) as client:
32+
try:
33+
response = await client.post(
34+
f"{API_BASE_URL}/compile-and-fix",
35+
json={'code': code, 'description': description, 'max_attempts': max_attempts}
36+
)
37+
response.raise_for_status()
38+
return response.text
39+
except httpx.HTTPError as e:
40+
print(f"HTTP error occurred: {e}")
41+
return f"Error calling compile-and-fix API: {str(e)}"
3542

3643
@mcp.tool()
3744
async def compile(code: str) -> str:

0 commit comments

Comments
 (0)