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