summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2016-06-09 13:11:02 +0100
committerErik Johnston <erikj@jki.re>2016-06-09 13:11:02 +0100
commit5ee5b655b21242085f25851fe279cd3c039c1441 (patch)
treec7263da86ba251900aad0d9e5c5e2a7a47ee6a11 /synapse
parentMerge pull request #860 from negzi/bug_fix_get_or_create_user (diff)
parent502 on /thumbnail when can't contact remote server (diff)
downloadsynapse-5ee5b655b21242085f25851fe279cd3c039c1441.tar.xz
Merge pull request #862 from matrix-org/erikj/media_remote_error
502 on /thumbnail when can't contact remote server
Diffstat (limited to 'synapse')
-rw-r--r--synapse/rest/media/v1/media_repository.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py
index d96bf9afe2..2468c3ac42 100644
--- a/synapse/rest/media/v1/media_repository.py
+++ b/synapse/rest/media/v1/media_repository.py
@@ -26,6 +26,7 @@ from .thumbnailer import Thumbnailer
 
 from synapse.http.matrixfederationclient import MatrixFederationHttpClient
 from synapse.util.stringutils import random_string
+from synapse.api.errors import SynapseError
 
 from twisted.internet import defer, threads
 
@@ -134,10 +135,15 @@ class MediaRepository(object):
                 request_path = "/".join((
                     "/_matrix/media/v1/download", server_name, media_id,
                 ))
-                length, headers = yield self.client.get_file(
-                    server_name, request_path, output_stream=f,
-                    max_size=self.max_upload_size,
-                )
+                try:
+                    length, headers = yield self.client.get_file(
+                        server_name, request_path, output_stream=f,
+                        max_size=self.max_upload_size,
+                    )
+                except Exception as e:
+                    logger.warn("Failed to fetch remoted media %r", e)
+                    raise SynapseError(502, "Failed to fetch remoted media")
+
             media_type = headers["Content-Type"][0]
             time_now_ms = self.clock.time_msec()