Skip to content
Snippets Groups Projects
Unverified Commit 10280fc9 authored by David Teller's avatar David Teller Committed by GitHub
Browse files

Uniformize spam-checker API, part 1: the `Code` enum. (#12703)

parent 71e8afe3
No related branches found
No related tags found
No related merge requests found
Convert namespace class `Codes` into a string enum.
\ No newline at end of file
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import logging import logging
import typing import typing
from enum import Enum
from http import HTTPStatus from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
...@@ -30,7 +31,11 @@ if typing.TYPE_CHECKING: ...@@ -30,7 +31,11 @@ if typing.TYPE_CHECKING:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Codes: class Codes(str, Enum):
"""
All known error codes, as an enum of strings.
"""
UNRECOGNIZED = "M_UNRECOGNIZED" UNRECOGNIZED = "M_UNRECOGNIZED"
UNAUTHORIZED = "M_UNAUTHORIZED" UNAUTHORIZED = "M_UNAUTHORIZED"
FORBIDDEN = "M_FORBIDDEN" FORBIDDEN = "M_FORBIDDEN"
...@@ -265,7 +270,9 @@ class UnrecognizedRequestError(SynapseError): ...@@ -265,7 +270,9 @@ class UnrecognizedRequestError(SynapseError):
"""An error indicating we don't understand the request you're trying to make""" """An error indicating we don't understand the request you're trying to make"""
def __init__( 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) super().__init__(400, msg, errcode)
......
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