mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 17:23:53 +01:00
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.
This commit is contained in:
parent
d1eb1b96e8
commit
aee8e6a95d
2 changed files with 6 additions and 5 deletions
1
changelog.d/9106.misc
Normal file
1
changelog.d/9106.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Reduce the scope of caught exceptions in `BlacklistingAgentWrapper`.
|
|
@ -32,7 +32,7 @@ from typing import (
|
||||||
|
|
||||||
import treq
|
import treq
|
||||||
from canonicaljson import encode_canonical_json
|
from canonicaljson import encode_canonical_json
|
||||||
from netaddr import IPAddress, IPSet
|
from netaddr import AddrFormatError, IPAddress, IPSet
|
||||||
from prometheus_client import Counter
|
from prometheus_client import Counter
|
||||||
from zope.interface import implementer, provider
|
from zope.interface import implementer, provider
|
||||||
|
|
||||||
|
@ -261,16 +261,16 @@ class BlacklistingAgentWrapper(Agent):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ip_address = IPAddress(h.hostname)
|
ip_address = IPAddress(h.hostname)
|
||||||
|
except AddrFormatError:
|
||||||
|
# Not an IP
|
||||||
|
pass
|
||||||
|
else:
|
||||||
if check_against_blacklist(
|
if check_against_blacklist(
|
||||||
ip_address, self._ip_whitelist, self._ip_blacklist
|
ip_address, self._ip_whitelist, self._ip_blacklist
|
||||||
):
|
):
|
||||||
logger.info("Blocking access to %s due to blacklist" % (ip_address,))
|
logger.info("Blocking access to %s due to blacklist" % (ip_address,))
|
||||||
e = SynapseError(403, "IP address blocked by IP blacklist entry")
|
e = SynapseError(403, "IP address blocked by IP blacklist entry")
|
||||||
return defer.fail(Failure(e))
|
return defer.fail(Failure(e))
|
||||||
except Exception:
|
|
||||||
# Not an IP
|
|
||||||
pass
|
|
||||||
|
|
||||||
return self._agent.request(
|
return self._agent.request(
|
||||||
method, uri, headers=headers, bodyProducer=bodyProducer
|
method, uri, headers=headers, bodyProducer=bodyProducer
|
||||||
|
|
Loading…
Reference in a new issue