|
@@ -14,6 +14,23 @@ router = APIRouter()
|
|
|
# limits: max_keepalive_connections 控制连接池大小
|
|
# limits: max_keepalive_connections 控制连接池大小
|
|
|
http_client = httpx.AsyncClient(timeout=10.0, limits=httpx.Limits(max_keepalive_connections=20, max_connections=100))
|
|
http_client = httpx.AsyncClient(timeout=10.0, limits=httpx.Limits(max_keepalive_connections=20, max_connections=100))
|
|
|
|
|
|
|
|
|
|
+def _extract_upstream_error_detail(resp: httpx.Response) -> str:
|
|
|
|
|
+ try:
|
|
|
|
|
+ data = resp.json()
|
|
|
|
|
+ if isinstance(data, dict):
|
|
|
|
|
+ detail = data.get("detail")
|
|
|
|
|
+ if detail:
|
|
|
|
|
+ return str(detail)
|
|
|
|
|
+ message = data.get("message")
|
|
|
|
|
+ if message:
|
|
|
|
|
+ return str(message)
|
|
|
|
|
+ return str(data)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ text = (resp.text or "").strip()
|
|
|
|
|
+ if text:
|
|
|
|
|
+ return text[:2000]
|
|
|
|
|
+ return "上游服务错误"
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@router.get("/scoring_config", summary="(管理员) 获取评分配置 [用户调用]")
|
|
@router.get("/scoring_config", summary="(管理员) 获取评分配置 [用户调用]")
|
|
|
async def proxy_get_scoring_config(current_user: dict = Depends(require_admin_user)):
|
|
async def proxy_get_scoring_config(current_user: dict = Depends(require_admin_user)):
|
|
@@ -27,7 +44,7 @@ async def proxy_get_scoring_config(current_user: dict = Depends(require_admin_us
|
|
|
logger.error(f"项目1返回错误: {resp.status_code} - {resp.text}")
|
|
logger.error(f"项目1返回错误: {resp.status_code} - {resp.text}")
|
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
|
status_code=resp.status_code,
|
|
status_code=resp.status_code,
|
|
|
- detail=resp.json().get("detail", "上游服务错误")
|
|
|
|
|
|
|
+ detail=_extract_upstream_error_detail(resp)
|
|
|
)
|
|
)
|
|
|
return resp.json()
|
|
return resp.json()
|
|
|
|
|
|
|
@@ -48,9 +65,14 @@ async def proxy_update_scoring_config(
|
|
|
resp = await http_client.put(target_url, json=config_data)
|
|
resp = await http_client.put(target_url, json=config_data)
|
|
|
|
|
|
|
|
if resp.status_code != 200:
|
|
if resp.status_code != 200:
|
|
|
- raise HTTPException(status_code=resp.status_code, detail=f"保存失败: {resp.json()['detail']}")
|
|
|
|
|
-
|
|
|
|
|
- return_data = {"detail": f"{resp.json()['message']}"}
|
|
|
|
|
|
|
+ raise HTTPException(status_code=resp.status_code, detail=f"保存失败: {_extract_upstream_error_detail(resp)}")
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ payload = resp.json()
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ payload = None
|
|
|
|
|
+ message = payload.get("message") if isinstance(payload, dict) else None
|
|
|
|
|
+ return_data = {"detail": f"{message or '保存成功'}"}
|
|
|
return JSONResponse(status_code=resp.status_code, content=return_data)
|
|
return JSONResponse(status_code=resp.status_code, content=return_data)
|
|
|
|
|
|
|
|
except httpx.RequestError as exc:
|
|
except httpx.RequestError as exc:
|
|
@@ -68,7 +90,8 @@ async def proxy_get_severity_names(defect_label: str = Query(..., description="
|
|
|
|
|
|
|
|
# 假设 settings.SCORE_SERVER_CONFIG_URL 是完整路径 ".../scoring_config"
|
|
# 假设 settings.SCORE_SERVER_CONFIG_URL 是完整路径 ".../scoring_config"
|
|
|
# 我们需要把它替换掉
|
|
# 我们需要把它替换掉
|
|
|
- base_url = settings.SCORE_SERVER_CONFIG_URL.rsplit('/', 1)[0]
|
|
|
|
|
|
|
+ temp = settings.SCORE_SERVER_CONFIG_URL
|
|
|
|
|
+ base_url = temp.rsplit('/', 1)[0]
|
|
|
final_url = f"{base_url}/severity_names"
|
|
final_url = f"{base_url}/severity_names"
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
@@ -79,7 +102,7 @@ async def proxy_get_severity_names(defect_label: str = Query(..., description="
|
|
|
logger.error(f"项目1返回错误: {resp.status_code} - {resp.text}")
|
|
logger.error(f"项目1返回错误: {resp.status_code} - {resp.text}")
|
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
|
status_code=resp.status_code,
|
|
status_code=resp.status_code,
|
|
|
- detail=resp.json().get("detail", "上游服务错误")
|
|
|
|
|
|
|
+ detail=_extract_upstream_error_detail(resp)
|
|
|
)
|
|
)
|
|
|
return resp.json()
|
|
return resp.json()
|
|
|
|
|
|