From e72b46c12727ef2fd9ba6595c17db824786adfb4 Mon Sep 17 00:00:00 2001 From: piglei Date: Tue, 23 Jul 2024 15:09:27 +0800 Subject: [PATCH] refactor: add missing error logs(view level) when getting repo failed --- apiserver/paasng/paasng/platform/sourcectl/views.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apiserver/paasng/paasng/platform/sourcectl/views.py b/apiserver/paasng/paasng/platform/sourcectl/views.py index ce33c85fd9..7f5496782a 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/views.py +++ b/apiserver/paasng/paasng/platform/sourcectl/views.py @@ -230,6 +230,11 @@ def get_repo_list(self, request, source_control_type): except AccessTokenForbidden as e: raise error_codes.CANNOT_GET_REPO.f(_("当前 AccessToken 无法获取到仓库列表,请检查后重试")) from e except Exception as e: + logger.exception( + "Unknown error occurred when getting repo list, user_id: %s, sourcectl_type: %s", + request.user.pk, + source_control_type, + ) raise error_codes.CANNOT_GET_REPO.f(_("访问源码仓库失败,请联系项目管理员")) from e return Response({"results": slzs.RepoSLZ(repos, many=True).data}) @@ -479,6 +484,7 @@ def get_compare_url(self, request, code, module_name, from_revision, to_revision except AccessTokenForbidden: raise error_codes.CANNOT_GET_REPO.f(_("AccessToken无权限访问该仓库, 请检查授权与其对应 Scope")) except Exception as e: + logger.exception("Unknown error occurred when getting compare url, user_id: %s", request.user.pk) raise error_codes.CANNOT_GET_REPO.f(_(f"仓库信息查询异常: {e}")) return Response({"result": compare_url}) @@ -543,7 +549,11 @@ def retrieve(self, request, code, module_name, smart_revision): except AccessTokenForbidden: raise error_codes.CANNOT_GET_REPO.f(_("AccessToken无权限访问该仓库, 请检查授权与其对应 Scope")) except Exception: - logger.exception("unable to fetch repo info") + logger.exception( + "Unknown error occurred when inspecting version, user_id: %s, version: %s", + request.user.pk, + smart_revision, + ) raise error_codes.CANNOT_GET_REPO.f(_("{module} 的仓库信息查询异常").format(module=module)) else: return Response(data)