Skip to content
Snippets Groups Projects
Unverified Commit aee8e6a9 authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

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.
parent d1eb1b96
No related branches found
No related tags found
No related merge requests found
Reduce the scope of caught exceptions in `BlacklistingAgentWrapper`.
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment