Skip to content

Commit 71e1e17

Browse files
committed
Return nicer error if trying to pull from non-existent user
Gitea serv will currently return an 500 if we try to pull from a repository where the owner does not exist. This PR checks for the UserNotExist Error when checking for the user and will return a NotFound error instead. Fix go-gitea#18225 Signed-off-by: Andrew Thornton <[email protected]>
1 parent d7c2a29 commit 71e1e17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

routers/private/serv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,17 @@ func ServCommand(ctx *context.PrivateContext) {
111111

112112
owner, err := user_model.GetUserByName(results.OwnerName)
113113
if err != nil {
114+
if user_model.IsErrUserNotExist(err) {
115+
// User is fetching/cloning a non-existent repository
116+
log.Error("Failed authentication attempt (cannot find repository: %s/%s) from %s", results.OwnerName, results.RepoName, ctx.RemoteAddr())
117+
ctx.JSON(http.StatusNotFound, private.ErrServCommand{
118+
Results: results,
119+
Err: fmt.Sprintf("Cannot find repository: %s/%s", results.OwnerName, results.RepoName),
120+
})
121+
return
122+
}
114123
log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
115-
ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{
124+
ctx.JSON(http.StatusForbidden, private.ErrServCommand{
116125
Results: results,
117126
Err: fmt.Sprintf("Unable to get repository owner: %s/%s %v", results.OwnerName, results.RepoName, err),
118127
})

0 commit comments

Comments
 (0)