fix: correct HTTP status codes and error handling in remaining handlers

- createPlaylistHandler: 200 → 201 Created, service errors → 500
- createSiteHandler: service/DB errors → 500 (was 400)
- saveStorageConfigHandler: service errors → 500 (was 400)
- SchedulerHandler.RunTask: task errors → 500 (was 400 with ErrInternal)
- aria2StatsHandler: service errors → 500 (was 400)
- organizeMediaHandler: service errors → 500 (was 400)
- testDownloadClientHandler: test failure → 200 with ok:false (was 400)
- testStorageConfigHandler: test failure → 200 with ok:false (was 400)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
soldosluka857
2026-05-30 02:47:57 +00:00
committed by Shuke
parent 260cc164a0
commit 4e5797f1f4
6 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -75,7 +75,7 @@ func deleteDownloadClientHandler(svc *service.Container) gin.HandlerFunc {
func testDownloadClientHandler(svc *service.Container) gin.HandlerFunc { func testDownloadClientHandler(svc *service.Container) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
if err := svc.DownloadClients.Test(c.Request.Context(), c.Param("id")); err != nil { if err := svc.DownloadClients.Test(c.Request.Context(), c.Param("id")); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"ok": false, "error": err.Error()}) c.JSON(http.StatusOK, gin.H{"ok": false, "error": err.Error()})
return return
} }
c.JSON(http.StatusOK, gin.H{"ok": true}) c.JSON(http.StatusOK, gin.H{"ok": true})
@@ -91,7 +91,7 @@ func aria2StatsHandler(svc *service.Container) gin.HandlerFunc {
} }
out, err := svc.DownloadClients.Aria2GlobalStats(c.Request.Context(), clientID) out, err := svc.DownloadClients.Aria2GlobalStats(c.Request.Context(), clientID)
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, out) c.JSON(http.StatusOK, out)
+1 -1
View File
@@ -13,7 +13,7 @@ func organizeMediaHandler(svc *service.Container) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
dst, err := svc.Organizer.OrganizeMedia(c.Request.Context(), c.Param("id")) dst, err := svc.Organizer.OrganizeMedia(c.Request.Context(), c.Param("id"))
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, gin.H{"path": dst}) c.JSON(http.StatusOK, gin.H{"path": dst})
+2 -2
View File
@@ -109,10 +109,10 @@ func createPlaylistHandler(svc *service.Container) gin.HandlerFunc {
c.Request.Context(), uid.(string), req.Name, req.IsPublic, c.Request.Context(), uid.(string), req.Name, req.IsPublic,
) )
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, pl) c.JSON(http.StatusCreated, pl)
} }
} }
+1 -1
View File
@@ -33,7 +33,7 @@ func (h *SchedulerHandler) RunTask(c *gin.Context) {
ctx := c.Request.Context() ctx := c.Request.Context()
if err := h.svc.Scheduler.RunNow(ctx, name); err != nil { if err := h.svc.Scheduler.RunNow(ctx, name); err != nil {
Error(c, http.StatusBadRequest, ErrInternal, "任务执行失败: "+err.Error()) Error(c, http.StatusInternalServerError, ErrInternal, "任务执行失败: "+err.Error())
return return
} }
+1 -1
View File
@@ -99,7 +99,7 @@ func createSiteHandler(svc *service.Container) gin.HandlerFunc {
Enabled: enabled, Enabled: enabled,
} }
if err := svc.Site.Create(c.Request.Context(), site); err != nil { if err := svc.Site.Create(c.Request.Context(), site); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusCreated, site) c.JSON(http.StatusCreated, site)
+2 -2
View File
@@ -50,7 +50,7 @@ func saveStorageConfigHandler(svc *service.Container) gin.HandlerFunc {
in.Type = c.Param("type") in.Type = c.Param("type")
row, err := svc.StorageCfg.Save(c.Request.Context(), in) row, err := svc.StorageCfg.Save(c.Request.Context(), in)
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, row) c.JSON(http.StatusOK, row)
@@ -67,7 +67,7 @@ func testStorageConfigHandler(svc *service.Container) gin.HandlerFunc {
} }
in.Type = c.Param("type") in.Type = c.Param("type")
if err := svc.StorageCfg.Test(c.Request.Context(), in); err != nil { if err := svc.StorageCfg.Test(c.Request.Context(), in); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"ok": false, "error": err.Error()}) c.JSON(http.StatusOK, gin.H{"ok": false, "error": err.Error()})
return return
} }
c.JSON(http.StatusOK, gin.H{"ok": true}) c.JSON(http.StatusOK, gin.H{"ok": true})