Skip to content

Commit

Permalink
Fix internal server error when updating 3pid address with invalid ema…
Browse files Browse the repository at this point in the history
…il (#18125)

When updating 3pid for a user email from admin api and sending invalid
email the server throws 500 internal server error.
changed to 400 Bad request and returned the error message

Signed-off-by: qashlan <ahmedelqashlan@gmail.com>
Signed-off-by: Ahmed Qashlan <ahmedelqashlan@gmail.com>
  • Loading branch information
qashlan authored Feb 12, 2025
1 parent aaffc35 commit 816054b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/18125.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug when updating a user 3pid with invalid returns 500 server error change to 400 with a message.
10 changes: 8 additions & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,10 @@ async def add_threepid(
# for the presence of an email address during password reset was
# case sensitive).
if medium == "email":
address = canonicalise_email(address)
try:
address = canonicalise_email(address)
except ValueError as e:
raise SynapseError(400, str(e))

await self.store.user_add_threepid(
user_id, medium, address, validated_at, self.hs.get_clock().time_msec()
Expand Down Expand Up @@ -1610,7 +1613,10 @@ async def delete_local_threepid(
"""
# 'Canonicalise' email addresses as per above
if medium == "email":
address = canonicalise_email(address)
try:
address = canonicalise_email(address)
except ValueError as e:
raise SynapseError(400, str(e))

await self.store.user_delete_threepid(user_id, medium, address)

Expand Down

0 comments on commit 816054b

Please sign in to comment.