Map Last.fm error codes to error atoms
This commit is contained in:
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user