summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Teller <D.O.Teller@gmail.com>2022-05-20 14:53:25 +0200
committerGitHub <noreply@github.com>2022-05-20 14:53:25 +0200
commit10280fc9437038f7ef715873e491d54b0a6d2208 (patch)
treeb5a44532021de9ea78b959750a677dc003db42c3
parentUpdate EventContext `get_current_event_ids` and `get_prev_event_ids` to accep... (diff)
downloadsynapse-10280fc9437038f7ef715873e491d54b0a6d2208.tar.xz
Uniformize spam-checker API, part 1: the `Code` enum. (#12703)
-rw-r--r--changelog.d/12703.misc1
-rw-r--r--synapse/api/errors.py11
2 files changed, 10 insertions, 2 deletions
diff --git a/changelog.d/12703.misc b/changelog.d/12703.misc
new file mode 100644
index 0000000000..9aaa1bbaa3
--- /dev/null
+++ b/changelog.d/12703.misc
@@ -0,0 +1 @@
+Convert namespace class `Codes` into a string enum.
\ No newline at end of file
diff --git a/synapse/api/errors.py b/synapse/api/errors.py
index cb3b7323d5..9614be6b4e 100644
--- a/synapse/api/errors.py
+++ b/synapse/api/errors.py
@@ -17,6 +17,7 @@
 
 import logging
 import typing
+from enum import Enum
 from http import HTTPStatus
 from typing import Any, Dict, List, Optional, Union
 
@@ -30,7 +31,11 @@ if typing.TYPE_CHECKING:
 logger = logging.getLogger(__name__)
 
 
-class Codes:
+class Codes(str, Enum):
+    """
+    All known error codes, as an enum of strings.
+    """
+
     UNRECOGNIZED = "M_UNRECOGNIZED"
     UNAUTHORIZED = "M_UNAUTHORIZED"
     FORBIDDEN = "M_FORBIDDEN"
@@ -265,7 +270,9 @@ class UnrecognizedRequestError(SynapseError):
     """An error indicating we don't understand the request you're trying to make"""
 
     def __init__(
-        self, msg: str = "Unrecognized request", errcode: str = Codes.UNRECOGNIZED
+        self,
+        msg: str = "Unrecognized request",
+        errcode: str = Codes.UNRECOGNIZED,
     ):
         super().__init__(400, msg, errcode)