feat(logging): add logging for archive move failures in handlers and episode repository
This commit is contained in:
parent
a0db346ab7
commit
a537eb4fc2
@ -2,6 +2,7 @@ package httpapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -232,6 +233,7 @@ func moveToArchiveHandler(svc episode.UseCases) gin.HandlerFunc {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("archive move failed for ids=%v: %v", ids, err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "move failed"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "move failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"watch-party-backend/internal/core/episode"
|
"watch-party-backend/internal/core/episode"
|
||||||
@ -190,6 +191,7 @@ func (r *pgxEpisodeRepo) MoveToArchive(ctx context.Context, ids []int64) (episod
|
|||||||
RETURNING id
|
RETURNING id
|
||||||
`, id, epNum, epTitle, seasonName, startTime, playback, currentEp, dateCreated).Scan(&archivedID)
|
`, id, epNum, epTitle, seasonName, startTime, playback, currentEp, dateCreated).Scan(&archivedID)
|
||||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
log.Printf("archive insert failed for id=%d: %v", id, err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
if err == nil {
|
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)
|
VALUES (nextval(pg_get_serial_sequence('current','id')), $1, $2, $3, $4, $5, $6, $7)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`, epNum, epTitle, seasonName, startTime, playback, currentEp, dateCreated).Scan(&archivedID); err != nil {
|
`, 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
|
return res, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete from current using the original id.
|
// Delete from current using the original id.
|
||||||
if _, err := tx.Exec(ctx, `DELETE FROM current WHERE id = $1`, id); err != nil {
|
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
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user