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

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

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12703.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert namespace class `Codes` into a string enum.
11 changes: 9 additions & 2 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import logging
import typing
from enum import Enum
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union

Expand All @@ -30,7 +31,11 @@
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"
Expand Down Expand Up @@ -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)

Expand Down