Skip to content

Commit d0921ef

Browse files
committed
Improve the server error on web routers
1 parent 5920b28 commit d0921ef

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

routers/web/repo/issue_pin.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ func IssuePinOrUnpin(ctx *context.Context) {
2323
// If we don't do this, it will crash when trying to add the pin event to the comment history
2424
err := issue.LoadRepo(ctx)
2525
if err != nil {
26-
ctx.Status(http.StatusInternalServerError)
27-
log.Error(err.Error())
26+
ctx.ServerError("LoadRepo", err)
2827
return
2928
}
3029

3130
// PinOrUnpin pins or unpins a Issue
3231
_, err = issues_model.GetIssuePin(ctx, issue)
3332
if err != nil && !db.IsErrNotExist(err) {
34-
ctx.Status(http.StatusInternalServerError)
35-
log.Error(err.Error())
33+
ctx.ServerError("GetIssuePin", err)
3634
return
3735
}
3836

@@ -46,8 +44,7 @@ func IssuePinOrUnpin(ctx *context.Context) {
4644
if issues_model.IsErrIssueMaxPinReached(err) {
4745
ctx.JSONError(ctx.Tr("repo.issues.max_pinned"))
4846
} else {
49-
ctx.Status(http.StatusInternalServerError)
50-
log.Error(err.Error())
47+
ctx.ServerError("Pin/Unpin failed", err)
5148
}
5249
return
5350
}
@@ -59,23 +56,20 @@ func IssuePinOrUnpin(ctx *context.Context) {
5956
func IssueUnpin(ctx *context.Context) {
6057
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
6158
if err != nil {
62-
ctx.Status(http.StatusInternalServerError)
63-
log.Error(err.Error())
59+
ctx.ServerError("GetIssueByIndex", err)
6460
return
6561
}
6662

6763
// If we don't do this, it will crash when trying to add the pin event to the comment history
6864
err = issue.LoadRepo(ctx)
6965
if err != nil {
70-
ctx.Status(http.StatusInternalServerError)
71-
log.Error(err.Error())
66+
ctx.ServerError("LoadRepo", err)
7267
return
7368
}
7469

7570
err = issues_model.UnpinIssue(ctx, issue, ctx.Doer)
7671
if err != nil {
77-
ctx.Status(http.StatusInternalServerError)
78-
log.Error(err.Error())
72+
ctx.ServerError("UnpinIssue", err)
7973
return
8074
}
8175

@@ -96,15 +90,13 @@ func IssuePinMove(ctx *context.Context) {
9690

9791
form := &movePinIssueForm{}
9892
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
99-
ctx.Status(http.StatusInternalServerError)
100-
log.Error(err.Error())
93+
ctx.ServerError("Decode", err)
10194
return
10295
}
10396

10497
issue, err := issues_model.GetIssueByID(ctx, form.ID)
10598
if err != nil {
106-
ctx.Status(http.StatusInternalServerError)
107-
log.Error(err.Error())
99+
ctx.ServerError("GetIssueByID", err)
108100
return
109101
}
110102

@@ -116,8 +108,7 @@ func IssuePinMove(ctx *context.Context) {
116108

117109
err = issues_model.MovePin(ctx, issue, form.Position)
118110
if err != nil {
119-
ctx.Status(http.StatusInternalServerError)
120-
log.Error(err.Error())
111+
ctx.ServerError("MovePin", err)
121112
return
122113
}
123114

0 commit comments

Comments
 (0)