diff --git a/changelog.d/20156.misc b/changelog.d/20156.misc new file mode 100644 index 0000000000..116a238d8f --- /dev/null +++ b/changelog.d/20156.misc @@ -0,0 +1 @@ +[MSC4140: Cancellable delayed events](https://github.com/matrix-org/matrix-spec-proposals/pull/4140): Update the error response for requesting to schedule a delayed event with a delay that exceeds the server-enforced maximum delay. diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 0c2b41225a..78fd8c3a60 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -137,6 +137,8 @@ class Codes(str, Enum): PROFILE_TOO_LARGE = "M_PROFILE_TOO_LARGE" KEY_TOO_LARGE = "M_KEY_TOO_LARGE" + DELAY_TOO_LARGE = "ORG.MATRIX.MSC4140_DELAY_TOO_LARGE" + # Part of MSC4155/MSC4380 INVITE_BLOCKED = "M_INVITE_BLOCKED" diff --git a/synapse/handlers/delayed_events.py b/synapse/handlers/delayed_events.py index cfaf16a30c..ac2da15112 100644 --- a/synapse/handlers/delayed_events.py +++ b/synapse/handlers/delayed_events.py @@ -373,9 +373,9 @@ class DelayedEventsHandler: requested_delay = delay.as_millis() max_delay = self._config.server.max_event_delay_duration.as_millis() raise SynapseError( - HTTPStatus.FORBIDDEN, + HTTPStatus.BAD_REQUEST, f"The requested delay ({requested_delay}ms) exceeds the allowed maximum ({max_delay}ms)", - Codes.FORBIDDEN, + Codes.DELAY_TOO_LARGE, ) self._event_creation_handler.validator.validate_builder( diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index a6f5043c92..78c960a537 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -2567,9 +2567,9 @@ class RoomDelayedEventTestCase(RoomBase): ).encode("ascii"), {"body": "test", "msgtype": "m.text"}, ) - self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, channel.result) + self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, channel.result) self.assertEqual( - Codes.FORBIDDEN, + "ORG.MATRIX.MSC4140_DELAY_TOO_LARGE", channel.json_body.get("errcode"), channel.json_body, )