From 2f335363b9a4b5e41d09ca2030181ae3521b3a1c Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 10 Aug 2021 13:44:21 -0500 Subject: [PATCH] When user cancels the command, respond with canceled If the cancel has not been fully handled in the body of the command, at least respond with canceled status and do not go to sentry. --- lib/command.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/command.rb b/lib/command.rb index b4ce5b9dce1c8bc2015bbff79436c0ad0ff6fba4..e07616691cd8f3adeec8298070a91e5de2364516 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -103,23 +103,26 @@ class Command protected def catch_after(promise) - promise.catch_only(FinalStanza) { |e| + promise.catch_only(Blather::Stanza::Iq::Command) { |iq| + next EMPromise.reject(iq) unless iq.cancel? + + finish(status: :canceled) + }.catch_only(FinalStanza) { |e| @blather << e.stanza }.catch do |e| log_error(e) - finish( - @format_error.call(e), type: :error - ).catch_only(FinalStanza) do |to_send| - @blather << to_send.stanza - end + send_final_error(e) + end + end + + def send_final_error(e) + finish(@format_error.call(e), type: :error).catch_only(FinalStanza) do |s| + @blather << s.stanza end end def log_error(e) - @log.error( - "Error raised during #{iq.node}: #{e.class}", - e - ) + @log.error("Error raised during #{iq.node}: #{e.class}", e) if e.is_a?(::Exception) sentry_hub.capture_exception(e) else