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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
184 changed files with 2100 additions and 2106 deletions

View file

@ -71,18 +71,18 @@ func ListNotifications(ctx *context.APIContext) {
totalCount, err := db.Count[activities_model.Notification](ctx, opts)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
nl, err := db.Find[activities_model.Notification](ctx, opts)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
err = activities_model.NotificationList(nl).LoadAttributes(ctx)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@ -133,7 +133,7 @@ func ReadNotifications(ctx *context.APIContext) {
if len(qLastRead) > 0 {
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
if err != nil {
ctx.Error(http.StatusBadRequest, "Parse", err)
ctx.APIError(http.StatusBadRequest, err)
return
}
if !tmpLastRead.IsZero() {
@ -150,7 +150,7 @@ func ReadNotifications(ctx *context.APIContext) {
}
nl, err := db.Find[activities_model.Notification](ctx, opts)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@ -164,7 +164,7 @@ func ReadNotifications(ctx *context.APIContext) {
for _, n := range nl {
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
_ = notif.LoadAttributes(ctx)