summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2021-12-15 22:38:29 -0600
committerEric Eastwood <erice@element.io>2021-12-15 22:38:29 -0600
commit1d0004312a3c77869808d7bd30b21c4e5c1572a8 (patch)
tree62ebebe9f7809bc0358447268debeed3127587ad /synapse/http/client.py
parentMerge branch 'develop' into madlittlemods/return-historical-events-in-order-f... (diff)
parentAdd type hints to `synapse/storage/databases/main/room.py` (#11575) (diff)
downloadsynapse-1d0004312a3c77869808d7bd30b21c4e5c1572a8.tar.xz
Merge branch 'develop' into madlittlemods/return-historical-events-in-order-from-backfill
Conflicts:
	synapse/handlers/message.py
	synapse/handlers/room_member.py
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r--synapse/http/client.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py

index b5a2d333a6..fbbeceabeb 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py
@@ -14,6 +14,7 @@ # limitations under the License. import logging import urllib.parse +from http import HTTPStatus from io import BytesIO from typing import ( TYPE_CHECKING, @@ -280,7 +281,9 @@ class BlacklistingAgentWrapper(Agent): ip_address, self._ip_whitelist, self._ip_blacklist ): logger.info("Blocking access to %s due to blacklist" % (ip_address,)) - e = SynapseError(403, "IP address blocked by IP blacklist entry") + e = SynapseError( + HTTPStatus.FORBIDDEN, "IP address blocked by IP blacklist entry" + ) return defer.fail(Failure(e)) return self._agent.request( @@ -719,7 +722,9 @@ class SimpleHttpClient: if response.code > 299: logger.warning("Got %d when downloading %s" % (response.code, url)) - raise SynapseError(502, "Got error %d" % (response.code,), Codes.UNKNOWN) + raise SynapseError( + HTTPStatus.BAD_GATEWAY, "Got error %d" % (response.code,), Codes.UNKNOWN + ) # TODO: if our Content-Type is HTML or something, just read the first # N bytes into RAM rather than saving it all to disk only to read it @@ -731,12 +736,14 @@ class SimpleHttpClient: ) except BodyExceededMaxSize: raise SynapseError( - 502, + HTTPStatus.BAD_GATEWAY, "Requested file is too large > %r bytes" % (max_size,), Codes.TOO_LARGE, ) except Exception as e: - raise SynapseError(502, ("Failed to download remote body: %s" % e)) from e + raise SynapseError( + HTTPStatus.BAD_GATEWAY, ("Failed to download remote body: %s" % e) + ) from e return ( length,