tianruci commited on
Commit
9c20da9
·
verified ·
1 Parent(s): 6b25ec8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -7,6 +7,7 @@ from fastapi.middleware.cors import CORSMiddleware
7
  from fastmcp.server import FastMCP
8
  from contextlib import asynccontextmanager
9
  from typing import List, Dict, Optional
 
10
 
11
  # 初始化 MCP 服务器(必须在 FastAPI 之前)
12
  mcp_server = FastMCP(name="GitHubTrendingAPI")
@@ -84,4 +85,8 @@ async def root():
84
  async def get_trending(num: int = 10):
85
  if not cached_trending:
86
  await fetch_github_trending()
87
- return {"trending": cached_trending[:num]}
 
 
 
 
 
7
  from fastmcp.server import FastMCP
8
  from contextlib import asynccontextmanager
9
  from typing import List, Dict, Optional
10
+ from fastapi.responses import JSONResponse
11
 
12
  # 初始化 MCP 服务器(必须在 FastAPI 之前)
13
  mcp_server = FastMCP(name="GitHubTrendingAPI")
 
85
  async def get_trending(num: int = 10):
86
  if not cached_trending:
87
  await fetch_github_trending()
88
+ return {"trending": cached_trending[:num]}
89
+
90
+ @app.exception_handler(404)
91
+ async def custom_404_handler(request, exc):
92
+ return JSONResponse(status_code=404, content={"detail": "Custom Not Found: Check path"})