When user cancels the command, respond with canceled

Stephen Paul Weber created

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.

Change summary

lib/command.rb | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

Detailed changes

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