Merge branch 'issue-17-invalid-lookup-uris' into 'master'
Add a nicer log entry when an invalid lookup URI is requested (#17) Closes #17 See merge request funkwhale/mopidy!13main
commit
5392f5b705
|
@ -375,9 +375,14 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
|
||||||
"artist": lambda id: client.list_tracks({"artist": id})["results"],
|
"artist": lambda id: client.list_tracks({"artist": id})["results"],
|
||||||
}
|
}
|
||||||
|
|
||||||
type, id = parse_uri(uri)
|
try:
|
||||||
payload = config[type](id)
|
type, id = parse_uri(uri)
|
||||||
return [convert_to_track(row, cache=self.cache) for row in payload]
|
except (IndexError, ValueError):
|
||||||
|
logger.info(f"Lookup failed: invalid uri '{uri}'")
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
payload = config[type](id)
|
||||||
|
return [convert_to_track(row, cache=self.cache) for row in payload]
|
||||||
|
|
||||||
|
|
||||||
def parse_uri(uri):
|
def parse_uri(uri):
|
||||||
|
|
|
@ -97,7 +97,7 @@ def test_parse_uri(uri, expected):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("type", ["track", "album", "artist"])
|
@pytest.mark.parametrize("type", ["track", "album", "artist"])
|
||||||
def test_parse_uri(type):
|
def test_to_ref(type):
|
||||||
obj = getattr(models, type.capitalize())(uri="hello:world", name="Hello")
|
obj = getattr(models, type.capitalize())(uri="hello:world", name="Hello")
|
||||||
expected = getattr(models.Ref, type)(uri=obj.uri, name=obj.name)
|
expected = getattr(models.Ref, type)(uri=obj.uri, name=obj.name)
|
||||||
assert mopidy_funkwhale.library.to_ref(obj) == expected
|
assert mopidy_funkwhale.library.to_ref(obj) == expected
|
||||||
|
|
Loading…
Reference in New Issue