Map Last.fm error codes to error atoms

This commit is contained in:
Claudio Ortolina
2024-12-27 19:54:10 +00:00
parent 1a0e505e51
commit db57195a0a
2 changed files with 25 additions and 10 deletions
+8 -8
View File
@@ -22,8 +22,7 @@ defmodule MusicLibrary.Artists do
def get_artist_info(artist) do
last_fm_config = last_fm_config()
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
case last_fm_config.api.get_artist_info(
{:musicbrainz_id, artist.musicbrainz_id},
last_fm_config
@@ -31,8 +30,9 @@ defmodule MusicLibrary.Artists do
{:ok, info} ->
{:ok, info}
# TODO: remap error codes
{:error, %{"error" => 6}} ->
{:error, :invalid_parameters} ->
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
last_fm_config.api.get_artist_info({:name, artist.name}, last_fm_config)
error ->
@@ -42,8 +42,7 @@ defmodule MusicLibrary.Artists do
def get_similar_artists(artist) do
last_fm_config = last_fm_config()
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
case last_fm_config.api.get_similar_artists(
{:musicbrainz_id, artist.musicbrainz_id},
last_fm_config
@@ -51,8 +50,9 @@ defmodule MusicLibrary.Artists do
{:ok, info} ->
{:ok, info}
# TODO: remap error codes
{:error, %{"error" => 6}} ->
{:error, :invalid_parameters} ->
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
last_fm_config.api.get_similar_artists({:name, artist.name}, last_fm_config)
error ->