diff options
author | Morgan Bazalgette <git@howl.moe> | 2018-01-10 22:34:17 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-01-10 23:34:17 +0200 |
commit | 65861900cda3bb6d9e2aa80b808b0000383c04b3 (patch) | |
tree | 8569d93b6ef092b30b35a4d4da906c6b6950e2ee /routers/repo/http.go | |
parent | 45c264f681e3f7e1a22a191029836a690959aac3 (diff) | |
download | gitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.tar.gz gitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.zip |
Handle refactor (#3339)
* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound
* Change Handle(403) to NotFound, avoid using macaron's NotFound
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r-- | routers/repo/http.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go index c1fdad5350..08ccf3ed65 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -120,7 +120,7 @@ func HTTP(ctx *context.Context) { authUser, err = models.UserSignIn(authUsername, authPasswd) if err != nil { if !models.IsErrUserNotExist(err) { - ctx.Handle(http.StatusInternalServerError, "UserSignIn error: %v", err) + ctx.ServerError("UserSignIn error: %v", err) return } } @@ -140,7 +140,7 @@ func HTTP(ctx *context.Context) { if models.IsErrUserNotExist(err) { ctx.HandleText(http.StatusUnauthorized, "invalid credentials") } else { - ctx.Handle(http.StatusInternalServerError, "GetUserByName", err) + ctx.ServerError("GetUserByName", err) } return } @@ -152,7 +152,7 @@ func HTTP(ctx *context.Context) { if models.IsErrAccessTokenNotExist(err) || models.IsErrAccessTokenEmpty(err) { ctx.HandleText(http.StatusUnauthorized, "invalid credentials") } else { - ctx.Handle(http.StatusInternalServerError, "GetAccessTokenBySha", err) + ctx.ServerError("GetAccessTokenBySha", err) } return } @@ -160,7 +160,7 @@ func HTTP(ctx *context.Context) { if isUsernameToken { authUser, err = models.GetUserByID(token.UID) if err != nil { - ctx.Handle(http.StatusInternalServerError, "GetUserByID", err) + ctx.ServerError("GetUserByID", err) return } } else if authUser.ID != token.UID { @@ -170,7 +170,7 @@ func HTTP(ctx *context.Context) { token.UpdatedUnix = util.TimeStampNow() if err = models.UpdateAccessToken(token); err != nil { - ctx.Handle(http.StatusInternalServerError, "UpdateAccessToken", err) + ctx.ServerError("UpdateAccessToken", err) } } else { _, err = models.GetTwoFactorByUID(authUser.ID) @@ -180,7 +180,7 @@ func HTTP(ctx *context.Context) { ctx.HandleText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page") return } else if !models.IsErrTwoFactorNotEnrolled(err) { - ctx.Handle(http.StatusInternalServerError, "IsErrTwoFactorNotEnrolled", err) + ctx.ServerError("IsErrTwoFactorNotEnrolled", err) return } } @@ -188,13 +188,13 @@ func HTTP(ctx *context.Context) { if !isPublicPull { has, err := models.HasAccess(authUser.ID, repo, accessMode) if err != nil { - ctx.Handle(http.StatusInternalServerError, "HasAccess", err) + ctx.ServerError("HasAccess", err) return } else if !has { if accessMode == models.AccessModeRead { has, err = models.HasAccess(authUser.ID, repo, models.AccessModeWrite) if err != nil { - ctx.Handle(http.StatusInternalServerError, "HasAccess2", err) + ctx.ServerError("HasAccess2", err) return } else if !has { ctx.HandleText(http.StatusForbidden, "User permission denied") @@ -501,7 +501,7 @@ func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc { dir, err := getGitRepoPath(m[1]) if err != nil { log.GitLogger.Error(4, err.Error()) - ctx.Handle(http.StatusNotFound, "HTTPBackend", err) + ctx.NotFound("HTTPBackend", err) return } @@ -510,7 +510,7 @@ func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc { } } - ctx.Handle(http.StatusNotFound, "HTTPBackend", nil) + ctx.NotFound("HTTPBackend", nil) return } } |