1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Errors don't set the HTTP status code

Some (if not all) just ignore the response if it's not a 200
and just consider the server borked.

Closes #192
This commit is contained in:
Alban Féron 2020-09-06 14:55:48 +02:00
parent b438bb0121
commit b511b1c647
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 11 additions and 11 deletions

View File

@ -3,7 +3,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2018-2019 Alban 'spl0k' Féron
# Copyright (C) 2018-2020 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -18,7 +18,7 @@ class SubsonicAPIException(HTTPException):
def get_response(self, environ=None):
rv = request.formatter.error(self.api_code, self.message)
rv.status_code = self.code
# rv.status_code = self.code
return rv
def __str__(self):
@ -122,5 +122,5 @@ class AggregateException(SubsonicAPIException):
rv = request.formatter(
"error", dict(code=list(codes)[0] if len(codes) == 1 else 0, error=errors)
)
rv.status_code = self.code
# rv.status_code = self.code
return rv

View File

@ -3,7 +3,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2018 Alban 'spl0k' Féron
# Copyright (C) 2018-2020 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -21,7 +21,7 @@ methods = (
def unsupported():
return GenericError("Not supported by Supysonic"), 501
return GenericError("Not supported by Supysonic")
for m in methods:

View File

@ -51,13 +51,13 @@ class ApiSetupTestCase(TestBase):
def __test_auth(self, method):
# non-existent user
rv = method("null", "null")
self.assertEqual(rv.status_code, 401)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="40"', rv.data)
# user request with bad password
rv = method("alice", "wrong password")
self.assertEqual(rv.status_code, 401)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="40"', rv.data)
@ -69,7 +69,7 @@ class ApiSetupTestCase(TestBase):
def test_auth_basic(self):
# No auth info
rv = self.client.get("/rest/ping.view?c=tests")
self.assertEqual(rv.status_code, 400)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="10"', rv.data)
@ -77,7 +77,7 @@ class ApiSetupTestCase(TestBase):
# Shouldn't accept 'enc:' passwords
rv = self.__basic_auth_get("alice", "enc:" + hexlify("Alic3"))
self.assertEqual(rv.status_code, 401)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="40"', rv.data)
@ -158,14 +158,14 @@ class ApiSetupTestCase(TestBase):
"/rest/getVideos.view",
query_string={"u": "alice", "p": "Alic3", "c": "tests"},
)
self.assertEqual(rv.status_code, 501)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="0"', rv.data)
rv = self.client.post(
"/rest/getVideos.view", data={"u": "alice", "p": "Alic3", "c": "tests"}
)
self.assertEqual(rv.status_code, 501)
self.assertEqual(rv.status_code, 200)
self.assertIn('status="failed"', rv.data)
self.assertIn('code="0"', rv.data)