Skip to content

Commit 8d067d8

Browse files
committed
make the error more safe
1 parent e0a9e25 commit 8d067d8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

routers/web/user/task.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package user
55

66
import (
77
"net/http"
8-
"strconv"
98

109
admin_model "code.gitea.io/gitea/models/admin"
1110
access_model "code.gitea.io/gitea/models/perm/access"
1211
"code.gitea.io/gitea/models/unit"
1312
"code.gitea.io/gitea/modules/json"
13+
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/services/context"
1515
)
1616

@@ -20,33 +20,36 @@ func TaskStatus(ctx *context.Context) {
2020
if err != nil {
2121
if admin_model.IsErrTaskDoesNotExist(err) {
2222
ctx.JSON(http.StatusNotFound, map[string]any{
23-
"error": "task `" + strconv.FormatInt(ctx.PathParamInt64("task"), 10) + "` does not exist",
23+
"err": "task does not exist or you do not have access to this task",
2424
})
2525
return
2626
}
27+
log.Error("GetMigratingTaskByID: %v", err)
2728
ctx.JSON(http.StatusInternalServerError, map[string]any{
28-
"err": err,
29+
"err": http.StatusText(http.StatusInternalServerError),
2930
})
3031
return
3132
}
3233

3334
if err := task.LoadRepo(ctx); err != nil {
35+
log.Error("LoadRepo: %v", err)
3436
ctx.JSON(http.StatusInternalServerError, map[string]any{
35-
"err": err,
37+
"err": http.StatusText(http.StatusInternalServerError),
3638
})
3739
return
3840
}
3941

4042
perm, err := access_model.GetUserRepoPermission(ctx, task.Repo, ctx.Doer)
4143
if err != nil {
44+
log.Error("LoadRepo: %v", err)
4245
ctx.JSON(http.StatusInternalServerError, map[string]any{
43-
"err": err,
46+
"err": http.StatusText(http.StatusInternalServerError),
4447
})
4548
return
4649
}
4750
if !perm.CanRead(unit.TypeCode) {
48-
ctx.JSON(http.StatusForbidden, map[string]any{
49-
"error": "you do not have access to this task",
51+
ctx.JSON(http.StatusNotFound, map[string]any{
52+
"err": "task does not exist or you do not have access to this task",
5053
})
5154
return
5255
}

services/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,4 @@ func (ctx *Context) JSONError(msg any) {
256256
panic(fmt.Sprintf("unsupported type: %T", msg))
257257
}
258258
}
259+

0 commit comments

Comments
 (0)