Improve error messages of non-str displayname/avatar_url (#8705)

This PR fixes two things:

* Corrects the copy/paste error of telling the client their displayname is wrong when they are submitting an `avatar_url`.
* Returns a `M_INVALID_PARAM` instead of `M_UNKNOWN` for non-str type parameters.

Reported by @t3chguy.
This commit is contained in:
Andrew Morgan 2020-11-02 18:01:09 +00:00 committed by GitHub
parent 59cc2472b3
commit e89bd3ea92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

1
changelog.d/8705.misc Normal file
View File

@ -0,0 +1 @@
Improve the error returned when a non-string displayname or avatar_url is used when updating a user's profile.

View File

@ -189,7 +189,9 @@ class ProfileHandler(BaseHandler):
) )
if not isinstance(new_displayname, str): if not isinstance(new_displayname, str):
raise SynapseError(400, "Invalid displayname") raise SynapseError(
400, "'displayname' must be a string", errcode=Codes.INVALID_PARAM
)
if len(new_displayname) > MAX_DISPLAYNAME_LEN: if len(new_displayname) > MAX_DISPLAYNAME_LEN:
raise SynapseError( raise SynapseError(
@ -273,7 +275,9 @@ class ProfileHandler(BaseHandler):
) )
if not isinstance(new_avatar_url, str): if not isinstance(new_avatar_url, str):
raise SynapseError(400, "Invalid displayname") raise SynapseError(
400, "'avatar_url' must be a string", errcode=Codes.INVALID_PARAM
)
if len(new_avatar_url) > MAX_AVATAR_URL_LEN: if len(new_avatar_url) > MAX_AVATAR_URL_LEN:
raise SynapseError( raise SynapseError(