mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Match the MSC error codes.
This commit is contained in:
parent
11cc48aab8
commit
adb64d863b
3 changed files with 10 additions and 4 deletions
|
@ -132,6 +132,10 @@ class Codes(str, Enum):
|
||||||
# connection.
|
# connection.
|
||||||
UNKNOWN_POS = "M_UNKNOWN_POS"
|
UNKNOWN_POS = "M_UNKNOWN_POS"
|
||||||
|
|
||||||
|
# Part of MSC4133
|
||||||
|
PROFILE_TOO_LARGE = "M_PROFILE_TOO_LARGE"
|
||||||
|
KEY_TOO_LARGE = "M_KEY_TOO_LARGE"
|
||||||
|
|
||||||
|
|
||||||
class CodeMessageException(RuntimeError):
|
class CodeMessageException(RuntimeError):
|
||||||
"""An exception with integer code, a message string attributes and optional headers.
|
"""An exception with integer code, a message string attributes and optional headers.
|
||||||
|
|
|
@ -292,7 +292,9 @@ class UnstableProfileRestServlet(RestServlet):
|
||||||
|
|
||||||
if len(field_name.encode("utf-8")) > MAX_CUSTOM_FIELD_LEN:
|
if len(field_name.encode("utf-8")) > MAX_CUSTOM_FIELD_LEN:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400, f"Field name too long: {field_name}", errcode=Codes.TOO_LARGE
|
400,
|
||||||
|
f"Field name too long: {field_name}",
|
||||||
|
errcode=Codes.KEY_TOO_LARGE,
|
||||||
)
|
)
|
||||||
|
|
||||||
propagate = _read_propagate(self.hs, request)
|
propagate = _read_propagate(self.hs, request)
|
||||||
|
@ -441,7 +443,7 @@ class UnstableProfileFieldRestServlet(RestServlet):
|
||||||
raise SynapseError(400, "Field name too short", errcode=Codes.INVALID_PARAM)
|
raise SynapseError(400, "Field name too short", errcode=Codes.INVALID_PARAM)
|
||||||
|
|
||||||
if len(field_name.encode("utf-8")) > MAX_CUSTOM_FIELD_LEN:
|
if len(field_name.encode("utf-8")) > MAX_CUSTOM_FIELD_LEN:
|
||||||
raise SynapseError(400, "Field name too long", errcode=Codes.TOO_LARGE)
|
raise SynapseError(400, "Field name too long", errcode=Codes.KEY_TOO_LARGE)
|
||||||
|
|
||||||
propagate = _read_propagate(self.hs, request)
|
propagate = _read_propagate(self.hs, request)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Tuple, cast
|
||||||
from canonicaljson import encode_canonical_json
|
from canonicaljson import encode_canonical_json
|
||||||
|
|
||||||
from synapse.api.constants import ProfileFields
|
from synapse.api.constants import ProfileFields
|
||||||
from synapse.api.errors import StoreError
|
from synapse.api.errors import Codes, StoreError
|
||||||
from synapse.storage._base import SQLBaseStore
|
from synapse.storage._base import SQLBaseStore
|
||||||
from synapse.storage.database import (
|
from synapse.storage.database import (
|
||||||
DatabasePool,
|
DatabasePool,
|
||||||
|
@ -366,7 +366,7 @@ class ProfileWorkerStore(SQLBaseStore):
|
||||||
total_bytes += len(encode_canonical_json({new_field_name: new_value}))
|
total_bytes += len(encode_canonical_json({new_field_name: new_value}))
|
||||||
|
|
||||||
if total_bytes > MAX_PROFILE_SIZE:
|
if total_bytes > MAX_PROFILE_SIZE:
|
||||||
raise StoreError(400, "Profile too large")
|
raise StoreError(400, "Profile too large", Codes.PROFILE_TOO_LARGE)
|
||||||
|
|
||||||
async def set_profile_displayname(
|
async def set_profile_displayname(
|
||||||
self, user_id: UserID, new_displayname: Optional[str]
|
self, user_id: UserID, new_displayname: Optional[str]
|
||||||
|
|
Loading…
Reference in a new issue