diff options
author | David Teller <D.O.Teller@gmail.com> | 2022-05-30 18:24:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-30 18:24:56 +0200 |
commit | af7db19e1e89e9b4ac4818c47b7f389ad46a7c9b (patch) | |
tree | 6752f92e20c89834c553fc5ff71e898e30c8f313 /synapse/api/errors.py | |
parent | demo: check if we are in a virtualenv before overriding PYTHONPATH (#12916) (diff) | |
download | synapse-af7db19e1e89e9b4ac4818c47b7f389ad46a7c9b.tar.xz |
Uniformize spam-checker API, part 3: Expand check_event_for_spam with the ability to return additional fields (#12846)
Signed-off-by: David Teller <davidt@element.io>
Diffstat (limited to 'synapse/api/errors.py')
-rw-r--r-- | synapse/api/errors.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 05e96843cf..54268e0889 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -146,7 +146,13 @@ class SynapseError(CodeMessageException): errcode: Matrix error code e.g 'M_FORBIDDEN' """ - def __init__(self, code: int, msg: str, errcode: str = Codes.UNKNOWN): + def __init__( + self, + code: int, + msg: str, + errcode: str = Codes.UNKNOWN, + additional_fields: Optional[Dict] = None, + ): """Constructs a synapse error. Args: @@ -156,9 +162,13 @@ class SynapseError(CodeMessageException): """ super().__init__(code, msg) self.errcode = errcode + if additional_fields is None: + self._additional_fields: Dict = {} + else: + self._additional_fields = dict(additional_fields) def error_dict(self) -> "JsonDict": - return cs_error(self.msg, self.errcode) + return cs_error(self.msg, self.errcode, **self._additional_fields) class InvalidAPICallError(SynapseError): @@ -183,14 +193,7 @@ class ProxiedRequestError(SynapseError): errcode: str = Codes.UNKNOWN, additional_fields: Optional[Dict] = None, ): - super().__init__(code, msg, errcode) - if additional_fields is None: - self._additional_fields: Dict = {} - else: - self._additional_fields = dict(additional_fields) - - def error_dict(self) -> "JsonDict": - return cs_error(self.msg, self.errcode, **self._additional_fields) + super().__init__(code, msg, errcode, additional_fields) class ConsentNotGivenError(SynapseError): |