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

Commit

Permalink
Reduce scope of exception handler. (#9106)
Browse files Browse the repository at this point in the history
Removes a bare `except Exception` clause and replaces it with
catching a specific exception around the portion that might throw.
  • Loading branch information
clokep authored Jan 13, 2021
1 parent d1eb1b9 commit aee8e6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/9106.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce the scope of caught exceptions in `BlacklistingAgentWrapper`.
10 changes: 5 additions & 5 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

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

Expand Down Expand Up @@ -261,16 +261,16 @@ def request(

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
Expand Down

0 comments on commit aee8e6a

Please sign in to comment.