subsonic: Catch ValueError when casting input parameters

A failed cast to int will raise ValueError, which is not currently caught
by the error checking code, leading to a crash. Fix this so a proper error
message can be returned.

Also add test for getting artist with non-numeric ID.
Signed-off-by: Toke Høiland-Jørgensen's avatarToke Høiland-Jørgensen <toke@toke.dk>
parent 6940d411
......@@ -38,7 +38,7 @@ def find_object(queryset, model_field="pk", field="id", cast=int):
)
try:
value = cast(raw_value)
except (TypeError, ValidationError):
except (ValueError, TypeError, ValidationError):
return response.Response(
{
"error": {
......
......@@ -102,6 +102,17 @@ def test_get_artist(f, db, logged_in_api_client, factories):
assert response.data == expected
@pytest.mark.parametrize("f", ["xml", "json"])
def test_get_invalid_artist(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-artist")
assert url.endswith("getArtist") is True
expected = {"error": {"code": 0, "message": 'For input string "asdf"'}}
response = logged_in_api_client.get(url, {"id": "asdf"})
assert response.status_code == 200
assert response.data == expected
@pytest.mark.parametrize("f", ["xml", "json"])
def test_get_artist_info2(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-artist-info2")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment