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 <toke@toke.dk>
This commit is contained in:
parent
6940d411d7
commit
2f46d83834
|
@ -38,7 +38,7 @@ def find_object(queryset, model_field="pk", field="id", cast=int):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
value = cast(raw_value)
|
value = cast(raw_value)
|
||||||
except (TypeError, ValidationError):
|
except (ValueError, TypeError, ValidationError):
|
||||||
return response.Response(
|
return response.Response(
|
||||||
{
|
{
|
||||||
"error": {
|
"error": {
|
||||||
|
|
|
@ -102,6 +102,17 @@ def test_get_artist(f, db, logged_in_api_client, factories):
|
||||||
assert response.data == expected
|
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"])
|
@pytest.mark.parametrize("f", ["xml", "json"])
|
||||||
def test_get_artist_info2(f, db, logged_in_api_client, factories):
|
def test_get_artist_info2(f, db, logged_in_api_client, factories):
|
||||||
url = reverse("api:subsonic-get-artist-info2")
|
url = reverse("api:subsonic-get-artist-info2")
|
||||||
|
|
Loading…
Reference in New Issue