Refactor error system (#33610)

This commit is contained in:
wxiaoguang
2025-02-17 14:13:17 +08:00
committed by GitHub
parent 69de5a65c2
commit f35850f48e
184 changed files with 2100 additions and 2106 deletions

View File

@ -46,7 +46,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
}
repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx, ctx.FormString("query"), &listOptions)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@ -86,33 +86,33 @@ func AdoptRepository(ctx *context.APIContext) {
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
// check not a repo
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
if has || !isDir {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}
if _, err := repo_service.AdoptRepository(ctx, ctx.Doer, ctxUser, repo_service.CreateRepoOptions{
Name: repoName,
IsPrivate: true,
}); err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@ -148,31 +148,31 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
// check not a repo
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
if has || !isDir {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}
if err := repo_service.DeleteUnadoptedRepository(ctx, ctx.Doer, ctxUser, repoName); err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}