diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index 673cc94a8..8a4423782 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -138,21 +138,24 @@ class SubsonicUpdate(BeetsPlugin): params=payload, timeout=10, ) - json = response.json() - - if ( - response.status_code == 200 - and json["subsonic-response"]["status"] == "ok" - ): - count = json["subsonic-response"]["scanStatus"]["count"] - self._log.info("Updating Subsonic; scanning {} tracks", count) - elif ( - response.status_code == 200 - and json["subsonic-response"]["status"] == "failed" - ): + response.raise_for_status() + try: + json = response.json() + except ValueError: self._log.error( - "Error: {[subsonic-response][error][message]}", json + "Invalid JSON from Subsonic: {}", response.text[:200] ) + return + if not (resp := json.get("subsonic-response")): + self._log.error("Missing 'subsonic-response' field: {}", json) + return + status = resp.get("status") + if status == "ok": + count = resp.get("scanStatus", {}).get("count", 0) + self._log.info("Updating Subsonic; scanning {} tracks", count) + elif status == "failed": + msg = resp.get("error", {}).get("message", "Unknown error") + self._log.error("Error: {}", msg) else: self._log.error("Error: {}", json) except Exception as error: diff --git a/docs/changelog.rst b/docs/changelog.rst index b9a5c1f3f..e85b4413b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -34,6 +34,9 @@ New features: Bug fixes: +- :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server + is unavailable or returns invalid JSON. Previously, failures were cryptic + (for instance, "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` - :doc:`plugins/inline`: Fix recursion error when an inline field definition shadows a built-in item field (e.g., redefining ``track_no``). Inline expressions now skip self-references during evaluation to avoid infinite