1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 02:08:36 +00:00

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

@@ -38,19 +38,19 @@ func ListTeams(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
if !ctx.Repo.Owner.IsOrganization() {
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
return
}
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
apiTeams, err := convert.ToTeams(ctx, teams, false)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@@ -89,7 +89,7 @@ func IsTeam(ctx *context.APIContext) {
// "$ref": "#/responses/error"
if !ctx.Repo.Owner.IsOrganization() {
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
return
}
@@ -101,14 +101,14 @@ func IsTeam(ctx *context.APIContext) {
if repo_service.HasRepository(ctx, team, ctx.Repo.Repository.ID) {
apiTeam, err := convert.ToTeam(ctx, team)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, apiTeam)
return
}
ctx.NotFound()
ctx.APIErrorNotFound()
}
// AddTeam add a team to a repository
@@ -185,10 +185,10 @@ func DeleteTeam(ctx *context.APIContext) {
func changeRepoTeam(ctx *context.APIContext, add bool) {
if !ctx.Repo.Owner.IsOrganization() {
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
}
if !ctx.Repo.Owner.RepoAdminChangeTeamAccess && !ctx.Repo.IsOwner() {
ctx.Error(http.StatusForbidden, "noAdmin", "user is nor repo admin nor owner")
ctx.APIError(http.StatusForbidden, "user is nor repo admin nor owner")
return
}
@@ -201,19 +201,19 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
var err error
if add {
if repoHasTeam {
ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name))
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("team '%s' is already added to repo", team.Name))
return
}
err = repo_service.TeamAddRepository(ctx, team, ctx.Repo.Repository)
} else {
if !repoHasTeam {
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("team '%s' was not added to repo", team.Name))
return
}
err = repo_service.RemoveRepositoryFromTeam(ctx, team, ctx.Repo.Repository.ID)
}
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@@ -224,10 +224,10 @@ func getTeamByParam(ctx *context.APIContext) *organization.Team {
team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.PathParam("team"))
if err != nil {
if organization.IsErrTeamNotExist(err) {
ctx.Error(http.StatusNotFound, "TeamNotExit", err)
ctx.APIError(http.StatusNotFound, err)
return nil
}
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return nil
}
return team