From 7600130c6bfe7bfbb2a912a90662bafec8bde822 Mon Sep 17 00:00:00 2001 From: wj00037 <1292876134@qq.com> Date: Mon, 28 Oct 2024 20:46:56 +0800 Subject: [PATCH] add fork err msg, add query url --- auth/client.go | 12 +++++++++++- auth/gitee.go | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/auth/client.go b/auth/client.go index e0a6348..aa3edf5 100644 --- a/auth/client.go +++ b/auth/client.go @@ -6,6 +6,9 @@ import ( "fmt" "io" "net/http" + "strings" + + "github.com/sirupsen/logrus" ) type Client struct { @@ -23,6 +26,13 @@ func getParsedResponse(method, path string, header http.Header, body io.Reader, panic(err) } defer response.Body.Close() + + if splitPath := strings.Split(path, "?"); len(splitPath) != 1 { + logrus.Infof("query %s with token | %d", splitPath[0], response.StatusCode) + } else { + logrus.Infof("query %s without token | %d", splitPath[0], response.StatusCode) + } + if response.StatusCode/100 != 2 { if response.StatusCode == http.StatusNotFound { return errors.New("not_found") @@ -31,7 +41,7 @@ func getParsedResponse(method, path string, header http.Header, body io.Reader, } else if response.StatusCode == http.StatusForbidden { return errors.New("forbidden") } - return fmt.Errorf("other error: %v", response.StatusCode) + return fmt.Errorf("system_error: %v", response.StatusCode) } data, err := io.ReadAll(response.Body) if err != nil { diff --git a/auth/gitee.go b/auth/gitee.go index 43623cb..f919620 100644 --- a/auth/gitee.go +++ b/auth/gitee.go @@ -118,7 +118,7 @@ func CheckRepoOwner(userInRepo UserInRepo) error { } } msg := "forbidden: repo has no permission to use this lfs server" - logrus.Error(fmt.Sprintf("CheckRepoOwner: %s", msg)) + logrus.Error(fmt.Sprintf("CheckRepoOwner | %s", msg)) return errors.New(msg) } @@ -160,7 +160,7 @@ func verifyUser(userInRepo UserInRepo) error { err := getParsedResponse("GET", path, headers, nil, &giteeUser) if err != nil { msg := err.Error() + ": verify user permission failed" - logrus.Error(fmt.Sprintf("verifyUser: %s", msg)) + logrus.Error(fmt.Sprintf("verifyUser | %s", msg)) return errors.New(msg) } @@ -170,21 +170,24 @@ func verifyUser(userInRepo UserInRepo) error { return nil } } - msg := "forbidden: user has no permission to upload" - logrus.Error(fmt.Sprintf("verifyUser: %s", msg)) - return errors.New(msg) + msg := fmt.Sprintf("forbidden: user %s has no permission to upload", userInRepo.Username) + remindMsg := " \n如果您正在向fork仓库上传文件,请确认您已修改过在仓库根路径下的" + + "`.lfsconfig`文件,文件里url所包含的仓库名称应改为您fork之后的仓库的名称。" + + "详阅:https://github.com/opensourceways/BigFiles/blob/master/docs/QuickStart.md" + logrus.Error(fmt.Sprintf("verifyUser | %s", msg)) + return errors.New(msg + remindMsg) } else if userInRepo.Operation == "download" { for _, v := range downloadPermissions { if giteeUser.Permission == v { return nil } } - msg := "forbidden: user has no permission to download" - logrus.Error(fmt.Sprintf("verifyUser: %s", msg)) + msg := fmt.Sprintf("forbidden: user %s has no permission to download", userInRepo.Username) + logrus.Error(fmt.Sprintf("verifyUser | %s", msg)) return errors.New(msg) } else { - msg := "other error: unknow operation" - logrus.Error(fmt.Sprintf("verifyUser: %s", msg)) + msg := "system_error: unknow operation" + logrus.Error(fmt.Sprintf("verifyUser | %s", msg)) return errors.New(msg) } }