Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Update the error code for duplicate annotation (#15075)
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh authored Feb 15, 2023
1 parent 06ba710 commit 5febf88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/15075.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update the error code returned when user sends a duplicate annotation.

4 changes: 4 additions & 0 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class Codes(str, Enum):

USER_AWAITING_APPROVAL = "ORG.MATRIX.MSC3866_USER_AWAITING_APPROVAL"

# Attempt to send a second annotation with the same event type & annotation key
# MSC2677
DUPLICATE_ANNOTATION = "M_DUPLICATE_ANNOTATION"


class CodeMessageException(RuntimeError):
"""An exception with integer code and message string attributes.
Expand Down
6 changes: 5 additions & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,11 @@ async def _validate_event_relation(self, event: EventBase) -> None:
relation.parent_id, event.type, aggregation_key, event.sender
)
if already_exists:
raise SynapseError(400, "Can't send same reaction twice")
raise SynapseError(
400,
"Can't send same reaction twice",
errcode=Codes.DUPLICATE_ANNOTATION,
)

# Don't attempt to start a thread if the parent event is a relation.
elif relation.rel_type == RelationTypes.THREAD:
Expand Down

0 comments on commit 5febf88

Please sign in to comment.