diff --git a/internal/playback/handler/handler.go b/internal/playback/handler/handler.go index 9cd1483..f5f3c54 100644 --- a/internal/playback/handler/handler.go +++ b/internal/playback/handler/handler.go @@ -205,7 +205,7 @@ func (h *PlaybackHandler) HandleUpsertSkipSegment(c *gin.Context) { userID = u.ID } if userID == "" { - c.Status(http.StatusUnauthorized) + c.JSON(http.StatusUnauthorized, gin.H{"error": "login required"}) return } @@ -217,12 +217,12 @@ func (h *PlaybackHandler) HandleUpsertSkipSegment(c *gin.Context) { EndTime float64 `json:"end_time"` } if err := c.ShouldBindJSON(&req); err != nil { - c.Status(http.StatusBadRequest) + c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"}) return } if err := h.svc.UpsertSkipSegmentOverride(c.Request.Context(), userID, req.MalID, req.Episode, req.SkipType, req.StartTime, req.EndTime); err != nil { - c.Status(http.StatusBadRequest) + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } diff --git a/static/player/skip/editor.ts b/static/player/skip/editor.ts index 15d62e6..a5fc07c 100644 --- a/static/player/skip/editor.ts +++ b/static/player/skip/editor.ts @@ -140,7 +140,12 @@ export const setupSegmentEditor = (): void => { }), }); if (!res.ok) { - setError(res.status === 401 ? 'Login required.' : 'Failed to save segment.'); + let message = res.status === 401 ? 'Login required.' : 'Failed to save segment.'; + try { + const payload = (await res.json()) as { error?: string }; + if (payload?.error) message = payload.error; + } catch {} + setError(message); return; }