feat(logging): add logging for archive move failures in handlers and episode repository

This commit is contained in:
Nik Afiq 2025-12-11 21:48:18 +09:00
parent a0db346ab7
commit a537eb4fc2
2 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package httpapi
import (
"errors"
"log"
"net/http"
"strconv"
"strings"
@ -232,6 +233,7 @@ func moveToArchiveHandler(svc episode.UseCases) gin.HandlerFunc {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
log.Printf("archive move failed for ids=%v: %v", ids, err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "move failed"})
return
}

View File

@ -3,6 +3,7 @@ package repo
import (
"context"
"errors"
"log"
"time"
"watch-party-backend/internal/core/episode"
@ -190,6 +191,7 @@ func (r *pgxEpisodeRepo) MoveToArchive(ctx context.Context, ids []int64) (episod
RETURNING id
`, id, epNum, epTitle, seasonName, startTime, playback, currentEp, dateCreated).Scan(&archivedID)
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
log.Printf("archive insert failed for id=%d: %v", id, err)
return res, err
}
if err == nil {
@ -204,12 +206,14 @@ func (r *pgxEpisodeRepo) MoveToArchive(ctx context.Context, ids []int64) (episod
VALUES (nextval(pg_get_serial_sequence('current','id')), $1, $2, $3, $4, $5, $6, $7)
RETURNING id
`, epNum, epTitle, seasonName, startTime, playback, currentEp, dateCreated).Scan(&archivedID); err != nil {
log.Printf("archive fallback insert failed for original id=%d: %v", id, err)
return res, err
}
}
// Delete from current using the original id.
if _, err := tx.Exec(ctx, `DELETE FROM current WHERE id = $1`, id); err != nil {
log.Printf("archive delete failed for id=%d: %v", id, err)
return res, err
}