diff --git a/synapse/rest/admin/registration_tokens.py b/synapse/rest/admin/registration_tokens.py
index 891b98c088..aba48f6e7b 100644
--- a/synapse/rest/admin/registration_tokens.py
+++ b/synapse/rest/admin/registration_tokens.py
@@ -14,7 +14,6 @@
import logging
import string
-from http import HTTPStatus
from typing import TYPE_CHECKING, Tuple
from synapse.api.errors import Codes, NotFoundError, SynapseError
@@ -78,7 +77,7 @@ class ListRegistrationTokensRestServlet(RestServlet):
await assert_requester_is_admin(self.auth, request)
valid = parse_boolean(request, "valid")
token_list = await self.store.get_registration_tokens(valid)
- return HTTPStatus.OK, {"registration_tokens": token_list}
+ return 200, {"registration_tokens": token_list}
class NewRegistrationTokenRestServlet(RestServlet):
@@ -124,20 +123,16 @@ class NewRegistrationTokenRestServlet(RestServlet):
if "token" in body:
token = body["token"]
if not isinstance(token, str):
- raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "token must be a string",
- Codes.INVALID_PARAM,
- )
+ raise SynapseError(400, "token must be a string", Codes.INVALID_PARAM)
if not (0 < len(token) <= 64):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
+ 400,
"token must not be empty and must not be longer than 64 characters",
Codes.INVALID_PARAM,
)
if not set(token).issubset(self.allowed_chars_set):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
+ 400,
"token must consist only of characters matched by the regex [A-Za-z0-9-_]",
Codes.INVALID_PARAM,
)
@@ -147,13 +142,11 @@ class NewRegistrationTokenRestServlet(RestServlet):
length = body.get("length", 16)
if not isinstance(length, int):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "length must be an integer",
- Codes.INVALID_PARAM,
+ 400, "length must be an integer", Codes.INVALID_PARAM
)
if not (0 < length <= 64):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
+ 400,
"length must be greater than zero and not greater than 64",
Codes.INVALID_PARAM,
)
@@ -169,7 +162,7 @@ class NewRegistrationTokenRestServlet(RestServlet):
or (isinstance(uses_allowed, int) and uses_allowed >= 0)
):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
+ 400,
"uses_allowed must be a non-negative integer or null",
Codes.INVALID_PARAM,
)
@@ -177,15 +170,11 @@ class NewRegistrationTokenRestServlet(RestServlet):
expiry_time = body.get("expiry_time", None)
if not isinstance(expiry_time, (int, type(None))):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "expiry_time must be an integer or null",
- Codes.INVALID_PARAM,
+ 400, "expiry_time must be an integer or null", Codes.INVALID_PARAM
)
if isinstance(expiry_time, int) and expiry_time < self.clock.time_msec():
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "expiry_time must not be in the past",
- Codes.INVALID_PARAM,
+ 400, "expiry_time must not be in the past", Codes.INVALID_PARAM
)
created = await self.store.create_registration_token(
@@ -193,9 +182,7 @@ class NewRegistrationTokenRestServlet(RestServlet):
)
if not created:
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- f"Token already exists: {token}",
- Codes.INVALID_PARAM,
+ 400, f"Token already exists: {token}", Codes.INVALID_PARAM
)
resp = {
@@ -205,7 +192,7 @@ class NewRegistrationTokenRestServlet(RestServlet):
"completed": 0,
"expiry_time": expiry_time,
}
- return HTTPStatus.OK, resp
+ return 200, resp
class RegistrationTokenRestServlet(RestServlet):
@@ -274,7 +261,7 @@ class RegistrationTokenRestServlet(RestServlet):
if token_info is None:
raise NotFoundError(f"No such registration token: {token}")
- return HTTPStatus.OK, token_info
+ return 200, token_info
async def on_PUT(self, request: SynapseRequest, token: str) -> Tuple[int, JsonDict]:
"""Update a registration token."""
@@ -290,7 +277,7 @@ class RegistrationTokenRestServlet(RestServlet):
or (isinstance(uses_allowed, int) and uses_allowed >= 0)
):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
+ 400,
"uses_allowed must be a non-negative integer or null",
Codes.INVALID_PARAM,
)
@@ -300,15 +287,11 @@ class RegistrationTokenRestServlet(RestServlet):
expiry_time = body["expiry_time"]
if not isinstance(expiry_time, (int, type(None))):
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "expiry_time must be an integer or null",
- Codes.INVALID_PARAM,
+ 400, "expiry_time must be an integer or null", Codes.INVALID_PARAM
)
if isinstance(expiry_time, int) and expiry_time < self.clock.time_msec():
raise SynapseError(
- HTTPStatus.BAD_REQUEST,
- "expiry_time must not be in the past",
- Codes.INVALID_PARAM,
+ 400, "expiry_time must not be in the past", Codes.INVALID_PARAM
)
new_attributes["expiry_time"] = expiry_time
@@ -324,7 +307,7 @@ class RegistrationTokenRestServlet(RestServlet):
if token_info is None:
raise NotFoundError(f"No such registration token: {token}")
- return HTTPStatus.OK, token_info
+ return 200, token_info
async def on_DELETE(
self, request: SynapseRequest, token: str
@@ -333,6 +316,6 @@ class RegistrationTokenRestServlet(RestServlet):
await assert_requester_is_admin(self.auth, request)
if await self.store.delete_registration_token(token):
- return HTTPStatus.OK, {}
+ return 200, {}
raise NotFoundError(f"No such registration token: {token}")
|