diff --git a/podcast/podcast.go b/podcast/podcast.go index 49b357c..d488a66 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -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) }