Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 10280fc

Browse files
authored
Uniformize spam-checker API, part 1: the Code enum. (#12703)
1 parent 71e8afe commit 10280fc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

changelog.d/12703.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert namespace class `Codes` into a string enum.

synapse/api/errors.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import logging
1919
import typing
20+
from enum import Enum
2021
from http import HTTPStatus
2122
from typing import Any, Dict, List, Optional, Union
2223

@@ -30,7 +31,11 @@
3031
logger = logging.getLogger(__name__)
3132

3233

33-
class Codes:
34+
class Codes(str, Enum):
35+
"""
36+
All known error codes, as an enum of strings.
37+
"""
38+
3439
UNRECOGNIZED = "M_UNRECOGNIZED"
3540
UNAUTHORIZED = "M_UNAUTHORIZED"
3641
FORBIDDEN = "M_FORBIDDEN"
@@ -265,7 +270,9 @@ class UnrecognizedRequestError(SynapseError):
265270
"""An error indicating we don't understand the request you're trying to make"""
266271

267272
def __init__(
268-
self, msg: str = "Unrecognized request", errcode: str = Codes.UNRECOGNIZED
273+
self,
274+
msg: str = "Unrecognized request",
275+
errcode: str = Codes.UNRECOGNIZED,
269276
):
270277
super().__init__(400, msg, errcode)
271278

0 commit comments

Comments
 (0)