Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5390 from matrix-org/erikj/dont_log_on_fail_to_ge…
Browse files Browse the repository at this point in the history
…t_file

Don't log exception when failing to fetch remote content.
  • Loading branch information
erikjohnston authored Jun 14, 2019
2 parents d053038 + 5009d98 commit e9344e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/5390.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix handling of failures fetching remote content to not log failures as exceptions.
13 changes: 9 additions & 4 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
from io import BytesIO

from six import text_type
from six import raise_from, text_type
from six.moves import urllib

import treq
Expand Down Expand Up @@ -542,10 +542,15 @@ def get_file(self, url, output_stream, max_size=None, headers=None):
length = yield make_deferred_yieldable(
_readBodyToFile(response, output_stream, max_size)
)
except SynapseError:
# This can happen e.g. because the body is too large.
raise
except Exception as e:
logger.exception("Failed to download body")
raise SynapseError(
502, ("Failed to download remote body: %s" % e), Codes.UNKNOWN
raise_from(
SynapseError(
502, ("Failed to download remote body: %s" % e),
),
e
)

defer.returnValue(
Expand Down
6 changes: 4 additions & 2 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ def _download_remote_file(self, server_name, media_id, file_id):
raise SynapseError(502, "Failed to fetch remote media")

except SynapseError:
logger.exception("Failed to fetch remote media %s/%s",
server_name, media_id)
logger.warn(
"Failed to fetch remote media %s/%s",
server_name, media_id,
)
raise
except NotRetryingDestination:
logger.warn("Not retrying destination %r", server_name)
Expand Down

0 comments on commit e9344e0

Please sign in to comment.