Error codes for filters
* add tests Signed-off-by: Alexander Maznev <alexander.maznev@gmail.com>
This commit is contained in:
parent
8681aff4f1
commit
d9350b0db8
|
@ -15,7 +15,7 @@
|
|||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import AuthError, SynapseError
|
||||
from synapse.api.errors import AuthError, SynapseError, StoreError, Codes
|
||||
from synapse.http.servlet import RestServlet, parse_json_object_from_request
|
||||
from synapse.types import UserID
|
||||
|
||||
|
@ -45,7 +45,7 @@ class GetFilterRestServlet(RestServlet):
|
|||
raise AuthError(403, "Cannot get filters for other users")
|
||||
|
||||
if not self.hs.is_mine(target_user):
|
||||
raise SynapseError(400, "Can only get filters for local users")
|
||||
raise AuthError(403, "Can only get filters for local users")
|
||||
|
||||
try:
|
||||
filter_id = int(filter_id)
|
||||
|
@ -59,8 +59,8 @@ class GetFilterRestServlet(RestServlet):
|
|||
)
|
||||
|
||||
defer.returnValue((200, filter.get_filter_json()))
|
||||
except KeyError:
|
||||
raise SynapseError(400, "No such filter")
|
||||
except (KeyError, StoreError):
|
||||
raise SynapseError(400, "No such filter", errcode=Codes.NOT_FOUND)
|
||||
|
||||
|
||||
class CreateFilterRestServlet(RestServlet):
|
||||
|
|
|
@ -19,7 +19,7 @@ from . import V2AlphaRestTestCase
|
|||
|
||||
from synapse.rest.client.v2_alpha import filter
|
||||
|
||||
from synapse.api.errors import StoreError
|
||||
from synapse.api.errors import StoreError, Codes
|
||||
|
||||
|
||||
class FilterTestCase(V2AlphaRestTestCase):
|
||||
|
@ -82,11 +82,20 @@ class FilterTestCase(V2AlphaRestTestCase):
|
|||
(code, response) = yield self.mock_resource.trigger_get(
|
||||
"/user/%s/filter/2" % (self.USER_ID)
|
||||
)
|
||||
self.assertEquals(404, code)
|
||||
self.assertEquals(400, code)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_get_filter_no_user(self):
|
||||
(code, response) = yield self.mock_resource.trigger_get(
|
||||
"/user/%s/filter/0" % (self.USER_ID)
|
||||
)
|
||||
self.assertEquals(404, code)
|
||||
self.assertEquals(400, code)
|
||||
self.assertEquals(response['errcode'], Codes.FORBIDDEN)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_get_filter_missing_id(self):
|
||||
(code, response) = yield self.mock_resource.trigger_get(
|
||||
"/user/%s/filter/0" % (self.USER_ID)
|
||||
)
|
||||
self.assertEquals(400, code)
|
||||
self.assertEquals(response['errcode'], Codes.NOT_FOUND)
|
||||
|
|
Loading…
Reference in New Issue