aboutsummaryrefslogtreecommitdiff
path: root/internal/route/api/v1/repo/milestone.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
committerᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
commit9e9ca66467116e9079a2639c00e9e623aca23015 (patch)
treedacdef5392608ff7107e4dd498959d4899e13e54 /internal/route/api/v1/repo/milestone.go
parent82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff)
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/route/api/v1/repo/milestone.go')
-rw-r--r--internal/route/api/v1/repo/milestone.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/internal/route/api/v1/repo/milestone.go b/internal/route/api/v1/repo/milestone.go
index 6f5fea17..a36a71d8 100644
--- a/internal/route/api/v1/repo/milestone.go
+++ b/internal/route/api/v1/repo/milestone.go
@@ -17,7 +17,7 @@ import (
func ListMilestones(c *context.APIContext) {
milestones, err := db.GetMilestonesByRepoID(c.Repo.Repository.ID)
if err != nil {
- c.ServerError("GetMilestonesByRepoID", err)
+ c.Error(err, "get milestones by repository ID")
return
}
@@ -31,7 +31,7 @@ func ListMilestones(c *context.APIContext) {
func GetMilestone(c *context.APIContext) {
milestone, err := db.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
- c.NotFoundOrServerError("GetMilestoneByRepoID", db.IsErrMilestoneNotExist, err)
+ c.NotFoundOrError(err, "get milestone by repository ID")
return
}
c.JSONSuccess(milestone.APIFormat())
@@ -51,7 +51,7 @@ func CreateMilestone(c *context.APIContext, form api.CreateMilestoneOption) {
}
if err := db.NewMilestone(milestone); err != nil {
- c.ServerError("NewMilestone", err)
+ c.Error(err, "new milestone")
return
}
c.JSON(http.StatusCreated, milestone.APIFormat())
@@ -60,7 +60,7 @@ func CreateMilestone(c *context.APIContext, form api.CreateMilestoneOption) {
func EditMilestone(c *context.APIContext, form api.EditMilestoneOption) {
milestone, err := db.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
- c.NotFoundOrServerError("GetMilestoneByRepoID", db.IsErrMilestoneNotExist, err)
+ c.NotFoundOrError(err, "get milestone by repository ID")
return
}
@@ -76,11 +76,11 @@ func EditMilestone(c *context.APIContext, form api.EditMilestoneOption) {
if form.State != nil {
if err = milestone.ChangeStatus(api.STATE_CLOSED == api.StateType(*form.State)); err != nil {
- c.ServerError("ChangeStatus", err)
+ c.Error(err, "change status")
return
}
} else if err = db.UpdateMilestone(milestone); err != nil {
- c.ServerError("UpdateMilestone", err)
+ c.Error(err, "update milestone")
return
}
@@ -89,7 +89,7 @@ func EditMilestone(c *context.APIContext, form api.EditMilestoneOption) {
func DeleteMilestone(c *context.APIContext) {
if err := db.DeleteMilestoneOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id")); err != nil {
- c.ServerError("DeleteMilestoneByRepoID", err)
+ c.Error(err, "delete milestone of repository by ID")
return
}
c.NoContent()