diff --git a/backend/app/main.py b/backend/app/main.py index 5a415a5..d81e1b1 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -9,6 +9,7 @@ import secrets import time import urllib.parse import urllib.request +import urllib.error import uuid import io import zipfile @@ -333,8 +334,11 @@ def _dingtalk_workbench_user(code: str) -> dict: try: with urllib.request.urlopen(token_request, timeout=10) as response: token_data = json.loads(response.read().decode("utf-8")) + except urllib.error.HTTPError as exc: + detail = exc.read().decode("utf-8", errors="replace")[:500] + raise HTTPException(status_code=502, detail=f"钉钉应用凭证校验失败:{detail}") from exc except Exception as exc: - raise HTTPException(status_code=502, detail="钉钉应用凭证校验失败,请稍后重试") from exc + raise HTTPException(status_code=502, detail=f"钉钉应用凭证校验失败:{exc}") from exc access_token = token_data.get("access_token") if not access_token: raise HTTPException(status_code=502, detail="钉钉未返回应用访问令牌,请检查应用权限") @@ -347,8 +351,11 @@ def _dingtalk_workbench_user(code: str) -> dict: try: with urllib.request.urlopen(user_request, timeout=10) as response: user_data = json.loads(response.read().decode("utf-8")) + except urllib.error.HTTPError as exc: + detail = exc.read().decode("utf-8", errors="replace")[:500] + raise HTTPException(status_code=502, detail=f"无法读取钉钉用户信息:{detail}") from exc except Exception as exc: - raise HTTPException(status_code=502, detail="无法读取钉钉用户信息,请检查应用免登权限") from exc + raise HTTPException(status_code=502, detail=f"无法读取钉钉用户信息:{exc}") from exc if user_data.get("errcode", 0) not in (0, None): raise HTTPException(status_code=502, detail=f"钉钉用户信息读取失败:{user_data.get('errmsg', '请检查应用权限')}") return user_data.get("result") or user_data diff --git a/frontend/index.html b/frontend/index.html index 32c33c2..0365e01 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,7 +7,7 @@
- +