scheduled_messages: Extract exception for invalid delivery time.

This commit is contained in:
Aman Agrawal
2025-05-02 10:22:44 +05:30
committed by Tim Abbott
parent 1af039d87b
commit ad9cb50183
3 changed files with 20 additions and 5 deletions

View File

@@ -16,7 +16,12 @@ from zerver.actions.message_send import (
from zerver.actions.uploads import check_attachment_reference_change, do_claim_attachments
from zerver.lib.addressee import Addressee
from zerver.lib.display_recipient import get_recipient_ids
from zerver.lib.exceptions import JsonableError, RealmDeactivatedError, UserDeactivatedError
from zerver.lib.exceptions import (
DeliveryTimeNotInFutureError,
JsonableError,
RealmDeactivatedError,
UserDeactivatedError,
)
from zerver.lib.markdown import render_message_markdown
from zerver.lib.message import SendMessageRequest, truncate_topic
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
@@ -153,7 +158,7 @@ def edit_scheduled_message(
# If the server failed to send the scheduled message, a new scheduled
# delivery timestamp (`deliver_at`) is required.
if scheduled_message_object.failed and deliver_at is None:
raise JsonableError(_("Scheduled delivery time must be in the future."))
raise DeliveryTimeNotInFutureError
# Get existing scheduled message's recipient IDs and recipient_type_name.
existing_recipient, existing_recipient_type_name = get_recipient_ids(

View File

@@ -766,3 +766,13 @@ class EmailAlreadyInUseError(JsonableError):
@override
def msg_format() -> str:
return _("Email is already in use.")
class DeliveryTimeNotInFutureError(JsonableError):
def __init__(self) -> None:
pass
@staticmethod
@override
def msg_format() -> str:
return _("Scheduled delivery time must be in the future.")

View File

@@ -10,7 +10,7 @@ from zerver.actions.scheduled_messages import (
delete_scheduled_message,
edit_scheduled_message,
)
from zerver.lib.exceptions import JsonableError
from zerver.lib.exceptions import DeliveryTimeNotInFutureError, JsonableError
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
from zerver.lib.request import RequestNotes
from zerver.lib.response import json_success
@@ -101,7 +101,7 @@ def update_scheduled_message_backend(
if scheduled_delivery_timestamp is not None:
deliver_at = timestamp_to_datetime(scheduled_delivery_timestamp)
if deliver_at <= timezone_now():
raise JsonableError(_("Scheduled delivery time must be in the future."))
raise DeliveryTimeNotInFutureError
sender = user_profile
client = RequestNotes.get_notes(request).client
@@ -151,7 +151,7 @@ def create_scheduled_message_backend(
deliver_at = timestamp_to_datetime(scheduled_delivery_timestamp)
if deliver_at <= timezone_now():
raise JsonableError(_("Scheduled delivery time must be in the future."))
raise DeliveryTimeNotInFutureError
sender = user_profile
client = RequestNotes.get_notes(request).client