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.
|
||||
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):
|
||||
"""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:
|
||||
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)
|
||||
|
@ -441,7 +443,7 @@ class UnstableProfileFieldRestServlet(RestServlet):
|
|||
raise SynapseError(400, "Field name too short", errcode=Codes.INVALID_PARAM)
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Tuple, cast
|
|||
from canonicaljson import encode_canonical_json
|
||||
|
||||
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.database import (
|
||||
DatabasePool,
|
||||
|
@ -366,7 +366,7 @@ class ProfileWorkerStore(SQLBaseStore):
|
|||
total_bytes += len(encode_canonical_json({new_field_name: new_value}))
|
||||
|
||||
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(
|
||||
self, user_id: UserID, new_displayname: Optional[str]
|
||||
|
|
Loading…
Reference in a new issue