refactor: pass cancellation from backend sgx

Amolith and Crush created

References: https://todo.sr.ht/~singpolyma/soprani.ca/380
Co-Authored-By: Crush <crush@charm.land>

Change summary

lib/backend_sgx.rb | 2 ++
sgx_jmp.rb         | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)

Detailed changes

lib/backend_sgx.rb 🔗

@@ -11,6 +11,8 @@ require_relative "form_to_h"
 class BackendSgx
 	COMMANDS_DISCO_NODE = "http://jabber.org/protocol/commands"
 
+	class CanceledError < StandardError; end
+
 	using FormToH
 
 	value_semantics do

sgx_jmp.rb 🔗

@@ -898,8 +898,10 @@ Command.new(
 			raise "PIN and confirm PIN must match." unless pin == confirm_pin
 
 			customer.set_port_out_pin(pin)
-		}.then do
+		}.then {
 			Command.finish("Your port-out PIN has been set.")
+		}.catch_only(BackendSgx::CanceledError) do |e|
+			Command.finish(e.message, status: :canceled)
 		end
 	end
 }.register(self).then(&CommandList.method(:register))