mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 08:48:37 +00:00
Refactor error system (#33610)
This commit is contained in:
@@ -107,9 +107,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound()
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -118,9 +118,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||
user, err := user_model.GetUserByName(ctx, ctx.PathParam("user"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -128,13 +128,13 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||
|
||||
// only admin and user for itself can change subscription
|
||||
if user.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.Doer.Name, user.Name))
|
||||
ctx.APIError(http.StatusForbidden, fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.Doer.Name, user.Name))
|
||||
return
|
||||
}
|
||||
|
||||
current, err := issues_model.CheckIssueWatch(ctx, user, issue)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||
|
||||
// Update watch state
|
||||
if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound()
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -198,7 +198,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||
|
||||
watching, err := issues_model.CheckIssueWatch(ctx, ctx.Doer, issue)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||
@@ -254,9 +254,9 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound()
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -264,7 +264,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||
|
||||
iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||
|
||||
users, err := user_model.GetUsersByIDs(ctx, userIDs)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUsersByIDs", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
apiUsers := make([]*api.User, 0, len(users))
|
||||
@@ -285,7 +285,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||
|
||||
count, err := issues_model.CountIssueWatchers(ctx, issue.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err)
|
||||
ctx.APIError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user