Skip to content

Improve "not found" error messages for API #34267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions routers/api/v1/repo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.
commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
if err != nil {
if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(identifier)
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
return
}
ctx.APIErrorInternal(err)
Expand Down Expand Up @@ -310,7 +310,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {

if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(sha)
ctx.APIErrorNotFound("commit doesn't exist: " + sha)
return
}
ctx.APIErrorInternal(err)
Expand Down
3 changes: 1 addition & 2 deletions routers/api/v1/repo/issue_tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package repo

import (
"errors"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -367,7 +366,7 @@ func DeleteTime(ctx *context.APIContext) {
return
}
if time.Deleted {
ctx.APIErrorNotFound(fmt.Errorf("tracked time [%d] already deleted", time.ID))
ctx.APIErrorNotFound("tracked time was already deleted")
return
}

Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func getNote(ctx *context.APIContext, identifier string) {
var note git.Note
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID.String(), &note); err != nil {
if git.IsErrNotExist(err) {
ctx.APIErrorNotFound(identifier)
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
return
}
ctx.APIErrorInternal(err)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func GetTag(ctx *context.APIContext) {

tag, err := ctx.Repo.GitRepo.GetTag(tagName)
if err != nil {
ctx.APIErrorNotFound(tagName)
ctx.APIErrorNotFound("tag doesn't exist: " + tagName)
return
}
ctx.JSON(http.StatusOK, convert.ToTag(ctx.Repo.Repository, tag))
Expand Down
2 changes: 1 addition & 1 deletion services/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
}
if ctx.Repo.Commit == nil || errors.Is(err, util.ErrNotExist) {
ctx.APIErrorNotFound(fmt.Errorf("not exist: '%s'", ctx.PathParam("*")))
ctx.APIErrorNotFound("unable to find a git ref")
return
} else if err != nil {
ctx.APIErrorInternal(err)
Expand Down