Skip to content

Commit 9c56429

Browse files
committed
don't crash on All Tracks page if API call to get album tracks fails
1 parent 6f7b54b commit 9c56429

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

backend/mediaprovider/subsonic/trackiterator.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,27 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
4141

4242
// fetch next album
4343
if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) {
44-
al := a.albumIter.Next()
45-
if al == nil {
46-
a.done = true
47-
return nil
48-
}
49-
alWithTracks, err := a.s.GetAlbum(al.ID)
50-
if err != nil {
51-
log.Printf("error fetching album: %s", err.Error())
52-
}
53-
if len(alWithTracks.Tracks) == 0 {
54-
// in the unlikely case of an album with zero tracks,
55-
// just call recursively to move to next album
56-
return a.Next()
44+
haveNextAlbum := false
45+
for !haveNextAlbum && !a.done {
46+
al := a.albumIter.Next()
47+
if al == nil {
48+
a.done = true
49+
return nil
50+
}
51+
alWithTracks, err := a.s.GetAlbum(al.ID)
52+
if err != nil || alWithTracks == nil {
53+
log.Printf("error fetching album: %s", err.Error())
54+
continue // try next album
55+
}
56+
haveNextAlbum = true
57+
if len(alWithTracks.Tracks) == 0 {
58+
// in the unlikely case of an album with zero tracks,
59+
// just call recursively to move to next album
60+
return a.Next()
61+
}
62+
a.curAlbum = alWithTracks
63+
a.curTrackIdx = 0
5764
}
58-
a.curAlbum = alWithTracks
59-
a.curTrackIdx = 0
6065
}
6166

6267
tr := a.curAlbum.Tracks[a.curTrackIdx]

0 commit comments

Comments
 (0)