summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2021-01-13 13:27:49 -0500
committerGitHub <noreply@github.com>2021-01-13 13:27:49 -0500
commitaee8e6a95d26391a8449409c836fa3965cdc6c51 (patch)
treedd55eda175481622a93f168946e088e8da5e1f6e /synapse/http/client.py
parentRegister the /devices endpoint on workers. (#9092) (diff)
downloadsynapse-aee8e6a95d26391a8449409c836fa3965cdc6c51.tar.xz
Reduce scope of exception handler. (#9106)
Removes a bare `except Exception` clause and replaces it with
catching a specific exception around the portion that might throw.
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r--synapse/http/client.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index 5f74ee1149..dc4b81ca60 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -32,7 +32,7 @@ from typing import (
 
 import treq
 from canonicaljson import encode_canonical_json
-from netaddr import IPAddress, IPSet
+from netaddr import AddrFormatError, IPAddress, IPSet
 from prometheus_client import Counter
 from zope.interface import implementer, provider
 
@@ -261,16 +261,16 @@ class BlacklistingAgentWrapper(Agent):
 
         try:
             ip_address = IPAddress(h.hostname)
-
+        except AddrFormatError:
+            # Not an IP
+            pass
+        else:
             if check_against_blacklist(
                 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")
                 return defer.fail(Failure(e))
-        except Exception:
-            # Not an IP
-            pass
 
         return self._agent.request(
             method, uri, headers=headers, bodyProducer=bodyProducer