spl0k / supysonic

Supysonic is a Python implementation of the Subsonic server API.
https://supysonic.readthedocs.io
GNU Affero General Public License v3.0
259 stars 57 forks source link

API should return HTTP 200 for failed/unknown endpoints #228

Closed jeffvli closed 2 years ago

jeffvli commented 2 years ago

Supysonic is currently returning 404s for non-implemented endpoints.

image

This is the same failed request handled by Airsonic (Subsonic does the same I believe).

image

This causes some inconsistencies when handling the endpoint on certain clients that use the endpoint. Would it be possible to change the resulting status on these methods? Thanks!

spl0k commented 2 years ago

Hello. This behavior is to be expected, and I'm planning on keeping it this way.

First of all --and that's valid for any HTTP client conversing with any HTTP server, not limited to Subsonic-compatibles-- clients shouldn't assume the server they're trying to reach will always answer with a 200 response, they should properly handle any response code or error. Failing to do so might lead the client to break, such as what was reported on jeffvli/sonixd#170. Handling any response code is one thing, but you should also watch out for the response body as sometimes you might get another format than the one you're expecting (HTML instead of JSON for example, this is especially true in some error cases). Even if Supysonic did answer with a 200-code response to any request (which is very wrong) there are still cases where your client might fail if it doesn't implement a proper error handling mechanism. Cases such as connectivity loss or some more subtle scenario where the server is behind a reverse-proxy and for some reason the server goes down; the proxy will still be reachable but will answer with an error in the 500 range.

Next you're comparing behaviors that aren't comparable. Supysonic targets the Subsonic API version 1.10.2 on which the getArtistInfo2 did not exists (it was added on version 1.11.0). The server you're comparing it to implements the version 1.15.0. Why should Supysonic respond with anything other than a 404 to something that doesn't exist? I wasn't able to find an Airsonic release on the 1.10.2 API to test it, but I did test it against the official Subsonic 4.9 (API 1.10.2) and no, it doesn't give you a 200 response to a non existing resource, you get an awful 404 which doesn't even respect the format you're asking for (HTML instead of what's requested with the f parameter). The API specification tells you that the server will answer with a version string of the API it implements, you can use it to deduce which endpoints are available or not.

jeffvli commented 2 years ago

Thanks for the detailed response and reasoning.