feat(podcast): ensure that any error path out of doPodcastDownload sets status (#672)
Some error paths out of this function are not setting the podcast status to 'error'. Move the deferred error checking earlier to ensure the status is set. Signed-off-by: Eric B Munson <eric@munsonfam.org>
This commit is contained in:
+7
-7
@@ -516,6 +516,13 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
podcastEpisode.Status = db.PodcastEpisodeStatusError
|
||||
_ = p.db.Save(podcastEpisode).Error
|
||||
}
|
||||
}()
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
return fmt.Errorf("fetch podcast audio: unexpected status %s", resp.Status)
|
||||
}
|
||||
@@ -537,13 +544,6 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
podcastEpisode.Status = db.PodcastEpisodeStatusError
|
||||
_ = p.db.Save(podcastEpisode).Error
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := io.Copy(file, resp.Body); err != nil {
|
||||
return fmt.Errorf("writing podcast episode: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user