summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2018-11-05 17:59:29 -0500
committerGitHub <noreply@github.com>2018-11-05 17:59:29 -0500
commitf1087106cf637e3c108c096ff789100bcbcc461c (patch)
treea6801dcbc02e2880298d194dd01c961dd5c189ce /synapse/rest
parentTests for user consent resource (#4140) (diff)
downloadsynapse-f1087106cf637e3c108c096ff789100bcbcc461c.tar.xz
handle empty backups according to latest spec proposal (#4123)
fixes #4056
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/client/v2_alpha/room_keys.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/synapse/rest/client/v2_alpha/room_keys.py b/synapse/rest/client/v2_alpha/room_keys.py
index 45b5817d8b..ab3f1bd21a 100644
--- a/synapse/rest/client/v2_alpha/room_keys.py
+++ b/synapse/rest/client/v2_alpha/room_keys.py
@@ -17,7 +17,7 @@ import logging
 
 from twisted.internet import defer
 
-from synapse.api.errors import Codes, SynapseError
+from synapse.api.errors import Codes, NotFoundError, SynapseError
 from synapse.http.servlet import (
     RestServlet,
     parse_json_object_from_request,
@@ -208,10 +208,25 @@ class RoomKeysServlet(RestServlet):
             user_id, version, room_id, session_id
         )
 
+        # Convert room_keys to the right format to return.
         if session_id:
-            room_keys = room_keys['rooms'][room_id]['sessions'][session_id]
+            # If the client requests a specific session, but that session was
+            # not backed up, then return an M_NOT_FOUND.
+            if room_keys['rooms'] == {}:
+                raise NotFoundError("No room_keys found")
+            else:
+                room_keys = room_keys['rooms'][room_id]['sessions'][session_id]
         elif room_id:
-            room_keys = room_keys['rooms'][room_id]
+            # If the client requests all sessions from a room, but no sessions
+            # are found, then return an empty result rather than an error, so
+            # that clients don't have to handle an error condition, and an
+            # empty result is valid.  (Similarly if the client requests all
+            # sessions from the backup, but in that case, room_keys is already
+            # in the right format, so we don't need to do anything about it.)
+            if room_keys['rooms'] == {}:
+                room_keys = {'sessions': {}}
+            else:
+                room_keys = room_keys['rooms'][room_id]
 
         defer.returnValue((200, room_keys))