summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-09-03 11:56:47 +0100
committerKegan Dougal <kegan@matrix.org>2014-09-03 11:56:47 +0100
commit10afd895c4318240d2afca19f34cd93440f43dd0 (patch)
tree8a9de121b6a63d3cd64a55bd98fac6538574a1fb /synapse/rest
parentUpdate API docs to use 'presence' key not 'state'. Fixed error messages when ... (diff)
downloadsynapse-10afd895c4318240d2afca19f34cd93440f43dd0.tar.xz
Edited /presence REST servlet to raise SynapseErrors to return a standard error response, rather than a string.
Diffstat (limited to '')
-rw-r--r--synapse/rest/presence.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/synapse/rest/presence.py b/synapse/rest/presence.py
index 967bb7d34f..69be6fe989 100644
--- a/synapse/rest/presence.py
+++ b/synapse/rest/presence.py
@@ -17,6 +17,7 @@
 """
 from twisted.internet import defer
 
+from synapse.api.errors import SynapseError
 from base import RestServlet, client_path_pattern
 
 import json
@@ -58,11 +59,15 @@ class PresenceStatusRestServlet(RestServlet):
 
             if "status_msg" in content:
                 state["status_msg"] = content.pop("status_msg")
+                if not isinstance(state["status_msg"], basestring):
+                    raise SynapseError(400, "status_msg must be a string.")
 
             if content:
                 raise KeyError()
+        except SynapseError as e:
+            raise e
         except:
-            defer.returnValue((400, "Unable to parse state"))
+            raise SynapseError(400, "Unable to parse state")
 
         yield self.handlers.presence_handler.set_state(
             target_user=user, auth_user=auth_user, state=state)
@@ -83,10 +88,10 @@ class PresenceListRestServlet(RestServlet):
         user = self.hs.parse_userid(user_id)
 
         if not user.is_mine:
-            defer.returnValue((400, "User not hosted on this Home Server"))
+            raise SynapseError(400, "User not hosted on this Home Server")
 
         if auth_user != user:
-            defer.returnValue((400, "Cannot get another user's presence list"))
+            raise SynapseError(400, "Cannot get another user's presence list")
 
         presence = yield self.handlers.presence_handler.get_presence_list(
             observer_user=user, accepted=True)
@@ -104,17 +109,17 @@ class PresenceListRestServlet(RestServlet):
         user = self.hs.parse_userid(user_id)
 
         if not user.is_mine:
-            defer.returnValue((400, "User not hosted on this Home Server"))
+            raise SynapseError(400, "User not hosted on this Home Server")
 
         if auth_user != user:
-            defer.returnValue((
-                400, "Cannot modify another user's presence list"))
+            raise SynapseError(
+                400, "Cannot modify another user's presence list")
 
         try:
             content = json.loads(request.content.read())
         except:
             logger.exception("JSON parse error")
-            defer.returnValue((400, "Unable to parse content"))
+            raise SynapseError(400, "Unable to parse content")
 
         deferreds = []