From d05a9d400060ae2f9b4ff9a2faee3a0f2ad74e6d Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 18 Jul 2023 18:01:27 +0000 Subject: [PATCH] reactions: Do not send server error reports for duplicate requests. --- web/src/reactions.js | 11 +++++++++-- web/tests/reactions.test.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/reactions.js b/web/src/reactions.js index a6d2637947..e3402949e4 100644 --- a/web/src/reactions.js +++ b/web/src/reactions.js @@ -85,8 +85,15 @@ function update_ui_and_send_reaction_ajax(message_id, reaction_info) { }, error(xhr) { view.waiting_for_server_request_ids.delete(reaction_request_id); - const response = channel.xhr_error_message("Error sending reaction", xhr); - blueslip.error(response); + if ( + xhr.responseJSON?.code === "REACTION_ALREADY_EXISTS" || + xhr.responseJSON?.code === "REACTION_DOES_NOT_EXIST" + ) { + // Don't send error report for simple precondition failures caused by race + // conditions; the user already got what they wanted + } else { + blueslip.error(channel.xhr_error_message("Error sending reaction", xhr)); + } }, }; diff --git a/web/tests/reactions.test.js b/web/tests/reactions.test.js index 09ccfbe6ac..1ebc54ae22 100644 --- a/web/tests/reactions.test.js +++ b/web/tests/reactions.test.js @@ -268,7 +268,7 @@ test("sending", ({override, override_rewire}) => { // Since this path calls blueslip.warn, we need to handle it. blueslip.expect("error", "XHR error message."); channel.xhr_error_message = () => "XHR error message."; - args.error(); + args.error({responseJSON: {msg: "Some error message"}}); } emoji_name = "alien"; // not set yet {