From 1451da1dee6f68f94ca043b17342b276b65ee131 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 10 Oct 2024 15:35:29 +0100 Subject: [PATCH] Don't fail import when cover fetch fails --- .../records/music_brainz/api_impl.ex | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/music_library/records/music_brainz/api_impl.ex b/lib/music_library/records/music_brainz/api_impl.ex index 503b02b0..76807cb5 100644 --- a/lib/music_library/records/music_brainz/api_impl.ex +++ b/lib/music_library/records/music_brainz/api_impl.ex @@ -232,8 +232,12 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do {:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 400) do Vix.Vips.Image.write_to_buffer(thumb, ".jpg") else - {:error, :not_found} -> {:ok, @fallback_cover} - error -> error + {:error, reason} -> + Logger.error( + "Failed to fetch cover art for #{musicbrainz_id}, reason: #{inspect(reason)}" + ) + + {:ok, @fallback_cover} end end @@ -273,13 +277,12 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do Logger.debug("Following redirect to #{location}") blob_get(location) - {:ok, response} when response.status == 404 -> - {:error, :not_found} + # all non-success responses can be treated as errors + {:ok, response} -> + {:error, response} - other -> - msg = "Failed to fetch data from #{url}, reason: #{inspect(other)}" - Logger.error(msg) - {:error, msg} + error -> + error end end