diff --git a/version.py b/version.py index da5b54b333..6f8adf99af 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 192 +API_FEATURE_LEVEL = 193 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/actions/reactions.py b/zerver/actions/reactions.py index e8b378966c..2247c3b13c 100644 --- a/zerver/actions/reactions.py +++ b/zerver/actions/reactions.py @@ -1,10 +1,8 @@ from typing import Any, Dict, Optional -from django.utils.translation import gettext as _ - from zerver.actions.create_user import create_historical_user_messages from zerver.lib.emoji import check_emoji_request, get_emoji_data -from zerver.lib.exceptions import JsonableError +from zerver.lib.exceptions import ReactionExistsError from zerver.lib.message import access_message, update_to_dict_cache from zerver.lib.stream_subscription import subscriber_ids_with_stream_history_access from zerver.models import Message, Reaction, Recipient, Stream, UserMessage, UserProfile @@ -115,7 +113,7 @@ def check_add_reaction( emoji_code=emoji_code, reaction_type=reaction_type, ).exists(): - raise JsonableError(_("Reaction already exists.")) + raise ReactionExistsError query = Reaction.objects.filter( message=message, emoji_code=emoji_code, reaction_type=reaction_type diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py index 51d57f557b..f736052fbc 100644 --- a/zerver/lib/exceptions.py +++ b/zerver/lib/exceptions.py @@ -40,6 +40,8 @@ class ErrorCode(Enum): UNAUTHORIZED = auto() REQUEST_TIMEOUT = auto() MOVE_MESSAGES_TIME_LIMIT_EXCEEDED = auto() + REACTION_ALREADY_EXISTS = auto() + REACTION_DOES_NOT_EXIST = auto() class JsonableError(Exception): @@ -503,3 +505,25 @@ class MessageMoveError(JsonableError): return _( "You only have permission to move the {total_messages_allowed_to_move}/{total_messages_in_topic} most recent messages in this topic." ) + + +class ReactionExistsError(JsonableError): + code = ErrorCode.REACTION_ALREADY_EXISTS + + def __init__(self) -> None: + pass + + @staticmethod + def msg_format() -> str: + return _("Reaction already exists.") + + +class ReactionDoesNotExistError(JsonableError): + code = ErrorCode.REACTION_DOES_NOT_EXIST + + def __init__(self) -> None: + pass + + @staticmethod + def msg_format() -> str: + return _("Reaction doesn't exist.") diff --git a/zerver/views/reactions.py b/zerver/views/reactions.py index 1df333c8bd..316d82eb0d 100644 --- a/zerver/views/reactions.py +++ b/zerver/views/reactions.py @@ -6,7 +6,7 @@ from django.utils.translation import gettext as _ from zerver.actions.reactions import check_add_reaction, do_remove_reaction from zerver.lib.emoji import get_emoji_data -from zerver.lib.exceptions import JsonableError +from zerver.lib.exceptions import JsonableError, ReactionDoesNotExistError from zerver.lib.message import access_message from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success @@ -65,7 +65,7 @@ def remove_reaction( emoji_code=emoji_code, reaction_type=reaction_type, ).exists(): - raise JsonableError(_("Reaction doesn't exist.")) + raise ReactionDoesNotExistError # Unlike adding reactions, while deleting a reaction, we don't # check whether the provided (emoji_type, emoji_code) pair is