don't crash on All Tracks page if API call to get album tracks fails
This commit is contained in:
@@ -41,22 +41,27 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
|
|||||||
|
|
||||||
// fetch next album
|
// fetch next album
|
||||||
if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) {
|
if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) {
|
||||||
al := a.albumIter.Next()
|
haveNextAlbum := false
|
||||||
if al == nil {
|
for !haveNextAlbum && !a.done {
|
||||||
a.done = true
|
al := a.albumIter.Next()
|
||||||
return nil
|
if al == nil {
|
||||||
|
a.done = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
alWithTracks, err := a.s.GetAlbum(al.ID)
|
||||||
|
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
|
||||||
|
return a.Next()
|
||||||
|
}
|
||||||
|
a.curAlbum = alWithTracks
|
||||||
|
a.curTrackIdx = 0
|
||||||
}
|
}
|
||||||
alWithTracks, err := a.s.GetAlbum(al.ID)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("error fetching album: %s", err.Error())
|
|
||||||
}
|
|
||||||
if len(alWithTracks.Tracks) == 0 {
|
|
||||||
// in the unlikely case of an album with zero tracks,
|
|
||||||
// just call recursively to move to next album
|
|
||||||
return a.Next()
|
|
||||||
}
|
|
||||||
a.curAlbum = alWithTracks
|
|
||||||
a.curTrackIdx = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tr := a.curAlbum.Tracks[a.curTrackIdx]
|
tr := a.curAlbum.Tracks[a.curTrackIdx]
|
||||||
|
|||||||
Reference in New Issue
Block a user