~singpolyma/sgx-jmp

2f335363b9a4b5e41d09ca2030181ae3521b3a1c — Stephen Paul Weber 1 year, 9 months ago e1e78a1
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.
1 files changed, 13 insertions(+), 10 deletions(-)

M lib/command.rb
M lib/command.rb => lib/command.rb +13 -10
@@ 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