Improve subsonicupdate server error

This commit is contained in:
AleksZyro
2026-07-13 11:58:50 +02:00
parent a85068bef8
commit 04f2c3e794
3 changed files with 32 additions and 1 deletions

View File

@@ -121,7 +121,18 @@ class SubsonicUpdate(BeetsPlugin):
try:
response = requests.get(url, params=payload, timeout=10)
json = response.json()
except requests.exceptions.JSONDecodeError:
self._log.error(
"Subsonic server returned a non-JSON response from {} "
"(HTTP {})",
url,
response.status_code,
)
return
except requests.exceptions.RequestException as error:
self._log.error("Error connecting to Subsonic server: {}", error)
return
try:
if (
response.status_code == 200
and json["subsonic-response"]["status"] == "ok"

View File

@@ -43,6 +43,8 @@ New features
Bug fixes
~~~~~~~~~
- :doc:`plugins/subsonicupdate`: Log a clearer error when the Subsonic server
returns a non-JSON response. :bug:`5635`
- :doc:`plugins/importfeeds`: ``beet import`` no longer aborts the whole run
when a symlink cannot be created (e.g. on Windows or a read-only directory);
the failure is logged and the import continues. :bug:`840`

View File

@@ -166,3 +166,21 @@ class SubsonicPluginTest(unittest.TestCase):
)
self.subsonicupdate.start_scan()
@responses.activate
def test_start_scan_failed_non_json_response(self):
"""Tests failed path based on a non-JSON server response."""
responses.add(
responses.GET,
"http://localhost:4040/rest/startScan",
status=503,
body="<html>server unavailable</html>",
content_type="text/html",
)
with self.assertLogs("beets", level="ERROR") as logs:
self.subsonicupdate.start_scan()
assert "Subsonic server returned a non-JSON response" in "\n".join(
logs.output
)