mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-27 19:36:07 +00:00
Improve "not found" error messages for API (#34267)
Make the message clear, for example: #34266
This commit is contained in:
parent
c2c04ffff7
commit
8aee07a064
@ -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)
|
||||
@ -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)
|
||||
|
@ -5,7 +5,6 @@ package repo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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(), ¬e); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.APIErrorNotFound(identifier)
|
||||
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
|
||||
return
|
||||
}
|
||||
ctx.APIErrorInternal(err)
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user