fix: surface segment save errors in editor
This commit is contained in:
@@ -205,7 +205,7 @@ func (h *PlaybackHandler) HandleUpsertSkipSegment(c *gin.Context) {
|
|||||||
userID = u.ID
|
userID = u.ID
|
||||||
}
|
}
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
c.Status(http.StatusUnauthorized)
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "login required"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,12 +217,12 @@ func (h *PlaybackHandler) HandleUpsertSkipSegment(c *gin.Context) {
|
|||||||
EndTime float64 `json:"end_time"`
|
EndTime float64 `json:"end_time"`
|
||||||
}
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.Status(http.StatusBadRequest)
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.svc.UpsertSkipSegmentOverride(c.Request.Context(), userID, req.MalID, req.Episode, req.SkipType, req.StartTime, req.EndTime); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,12 @@ export const setupSegmentEditor = (): void => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user