Skip to content

Commit 8aee07a

Browse files
authored
Improve "not found" error messages for API (#34267)
Make the message clear, for example: #34266
1 parent c2c04ff commit 8aee07a

File tree

5 files changed

+6
-7
lines changed

5 files changed

+6
-7
lines changed

routers/api/v1/repo/commits.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.
7575
commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
7676
if err != nil {
7777
if git.IsErrNotExist(err) {
78-
ctx.APIErrorNotFound(identifier)
78+
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
7979
return
8080
}
8181
ctx.APIErrorInternal(err)
@@ -310,7 +310,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
310310

311311
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
312312
if git.IsErrNotExist(err) {
313-
ctx.APIErrorNotFound(sha)
313+
ctx.APIErrorNotFound("commit doesn't exist: " + sha)
314314
return
315315
}
316316
ctx.APIErrorInternal(err)

routers/api/v1/repo/issue_tracked_time.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package repo
55

66
import (
77
"errors"
8-
"fmt"
98
"net/http"
109
"time"
1110

@@ -367,7 +366,7 @@ func DeleteTime(ctx *context.APIContext) {
367366
return
368367
}
369368
if time.Deleted {
370-
ctx.APIErrorNotFound(fmt.Errorf("tracked time [%d] already deleted", time.ID))
369+
ctx.APIErrorNotFound("tracked time was already deleted")
371370
return
372371
}
373372

routers/api/v1/repo/notes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func getNote(ctx *context.APIContext, identifier string) {
7979
var note git.Note
8080
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID.String(), &note); err != nil {
8181
if git.IsErrNotExist(err) {
82-
ctx.APIErrorNotFound(identifier)
82+
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
8383
return
8484
}
8585
ctx.APIErrorInternal(err)

routers/api/v1/repo/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func GetTag(ctx *context.APIContext) {
150150

151151
tag, err := ctx.Repo.GitRepo.GetTag(tagName)
152152
if err != nil {
153-
ctx.APIErrorNotFound(tagName)
153+
ctx.APIErrorNotFound("tag doesn't exist: " + tagName)
154154
return
155155
}
156156
ctx.JSON(http.StatusOK, convert.ToTag(ctx.Repo.Repository, tag))

services/context/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
313313
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
314314
}
315315
if ctx.Repo.Commit == nil || errors.Is(err, util.ErrNotExist) {
316-
ctx.APIErrorNotFound(fmt.Errorf("not exist: '%s'", ctx.PathParam("*")))
316+
ctx.APIErrorNotFound("unable to find a git ref")
317317
return
318318
} else if err != nil {
319319
ctx.APIErrorInternal(err)

0 commit comments

Comments
 (0)