don't crash on All Tracks page if API call to get album tracks fails

This commit is contained in:
Drew Weymouth
2025-07-12 09:10:13 -07:00
parent 6f7b54b779
commit 9c56429ed4
@@ -41,15 +41,19 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
// fetch next album
if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) {
haveNextAlbum := false
for !haveNextAlbum && !a.done {
al := a.albumIter.Next()
if al == nil {
a.done = true
return nil
}
alWithTracks, err := a.s.GetAlbum(al.ID)
if err != nil {
if err != nil || alWithTracks == nil {
log.Printf("error fetching album: %s", err.Error())
continue // try next album
}
haveNextAlbum = true
if len(alWithTracks.Tracks) == 0 {
// in the unlikely case of an album with zero tracks,
// just call recursively to move to next album
@@ -58,6 +62,7 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
a.curAlbum = alWithTracks
a.curTrackIdx = 0
}
}
tr := a.curAlbum.Tracks[a.curTrackIdx]
a.curTrackIdx += 1