fix: stop swallowing errors
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"mal/integrations/jikan"
|
"mal/integrations/jikan"
|
||||||
"mal/internal/db"
|
"mal/internal/db"
|
||||||
"mal/internal/domain"
|
"mal/internal/domain"
|
||||||
|
"mal/internal/observability"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -187,6 +188,13 @@ func (s *animeService) GetDiscoverForYou(ctx context.Context, userID string) (do
|
|||||||
for i := range limit {
|
for i := range limit {
|
||||||
anime, fetchErr := s.jikan.GetAnimeByID(ctx, rankedIDs[i].id)
|
anime, fetchErr := s.jikan.GetAnimeByID(ctx, rankedIDs[i].id)
|
||||||
if fetchErr != nil {
|
if fetchErr != nil {
|
||||||
|
observability.Warn(
|
||||||
|
"recommendation_anime_fetch_failed",
|
||||||
|
"anime",
|
||||||
|
"",
|
||||||
|
map[string]any{"anime_id": rankedIDs[i].id},
|
||||||
|
fetchErr,
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
animes = append(animes, anime)
|
animes = append(animes, anime)
|
||||||
@@ -249,6 +257,13 @@ func (s *animeService) GetAiringSchedule(ctx context.Context, userID string) ([]
|
|||||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
observability.Warn(
|
||||||
|
"schedule_partial_fetch_failed",
|
||||||
|
"anime",
|
||||||
|
"",
|
||||||
|
map[string]any{"user_id": userID, "count": len(ids)},
|
||||||
|
err,
|
||||||
|
)
|
||||||
return animes, nil
|
return animes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"mal/integrations/jikan"
|
"mal/integrations/jikan"
|
||||||
"mal/internal/db"
|
"mal/internal/db"
|
||||||
"mal/internal/domain"
|
"mal/internal/domain"
|
||||||
|
"mal/internal/observability"
|
||||||
"mal/pkg/net/limits"
|
"mal/pkg/net/limits"
|
||||||
"mal/pkg/net/useragent"
|
"mal/pkg/net/useragent"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -316,10 +317,12 @@ func (s *playbackService) CompleteAnime(ctx context.Context, userID string, anim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = s.repo.DeleteContinueWatchingEntry(ctx, db.DeleteContinueWatchingEntryParams{
|
if err := s.repo.DeleteContinueWatchingEntry(ctx, db.DeleteContinueWatchingEntryParams{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := s.repo.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
if err := s.repo.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
@@ -328,12 +331,20 @@ func (s *playbackService) CompleteAnime(ctx context.Context, userID string, anim
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_ = s.auditSvc.Record(ctx, domain.AuditEvent{
|
if err := s.auditSvc.Record(ctx, domain.AuditEvent{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Action: "watch_completed",
|
Action: "watch_completed",
|
||||||
ResourceType: "anime",
|
ResourceType: "anime",
|
||||||
ResourceID: strconv.FormatInt(animeID, 10),
|
ResourceID: strconv.FormatInt(animeID, 10),
|
||||||
})
|
}); err != nil {
|
||||||
|
observability.Warn(
|
||||||
|
"audit_record_failed",
|
||||||
|
"playback",
|
||||||
|
"",
|
||||||
|
map[string]any{"user_id": userID, "anime_id": animeID, "action": "watch_completed"},
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,15 +23,18 @@ func (s *watchlistService) UpdateEntry(ctx context.Context, userID string, anime
|
|||||||
_, err := s.repo.GetAnime(ctx, animeID)
|
_, err := s.repo.GetAnime(ctx, animeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
anime, err := s.jikan.GetAnimeByID(ctx, int(animeID))
|
anime, err := s.jikan.GetAnimeByID(ctx, int(animeID))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
_, _ = s.repo.UpsertAnime(ctx, db.UpsertAnimeParams{
|
return err
|
||||||
|
}
|
||||||
|
if _, err := s.repo.UpsertAnime(ctx, db.UpsertAnimeParams{
|
||||||
ID: int64(anime.MalID),
|
ID: int64(anime.MalID),
|
||||||
TitleOriginal: anime.Title,
|
TitleOriginal: anime.Title,
|
||||||
TitleEnglish: sql.NullString{String: anime.TitleEnglish, Valid: anime.TitleEnglish != ""},
|
TitleEnglish: sql.NullString{String: anime.TitleEnglish, Valid: anime.TitleEnglish != ""},
|
||||||
TitleJapanese: sql.NullString{String: anime.TitleJapanese, Valid: anime.TitleJapanese != ""},
|
TitleJapanese: sql.NullString{String: anime.TitleJapanese, Valid: anime.TitleJapanese != ""},
|
||||||
ImageUrl: anime.ImageURL(),
|
ImageUrl: anime.ImageURL(),
|
||||||
Airing: sql.NullBool{Bool: anime.Airing, Valid: true},
|
Airing: sql.NullBool{Bool: anime.Airing, Valid: true},
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,10 +99,12 @@ func (s *watchlistService) GetContinueWatchingEntry(ctx context.Context, userID
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *watchlistService) DeleteContinueWatching(ctx context.Context, userID string, animeID int64) error {
|
func (s *watchlistService) DeleteContinueWatching(ctx context.Context, userID string, animeID int64) error {
|
||||||
_ = s.repo.DeleteContinueWatchingEntry(ctx, db.DeleteContinueWatchingEntryParams{
|
if err := s.repo.DeleteContinueWatchingEntry(ctx, db.DeleteContinueWatchingEntryParams{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return s.repo.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
return s.repo.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
|
|||||||
Reference in New Issue
Block a user