ErrorToSend => FinalStanza

Stephen Paul Weber created

Change summary

lib/command.rb              | 18 +++++++++++++++---
lib/error_to_send.rb        | 10 ----------
lib/registration.rb         |  1 -
lib/web_register_manager.rb |  2 --
sgx_jmp.rb                  |  3 +--
5 files changed, 16 insertions(+), 18 deletions(-)

Detailed changes

lib/command.rb 🔗

@@ -27,6 +27,14 @@ class Command
 	end
 
 	class Execution
+		class FinalStanza
+			attr_reader :stanza
+
+			def initialize(stanza)
+				@stanza = stanza
+			end
+		end
+
 		attr_reader :customer_repo, :log, :iq
 
 		def initialize(customer_repo, blather, format_error, iq)
@@ -64,7 +72,7 @@ class Command
 				reply.note_type = type
 				reply.note_text = text
 			end
-			raise ErrorToSend, reply
+			EMPromise.reject(FinalStanza.new(reply))
 		end
 
 		def sentry_hub
@@ -95,11 +103,15 @@ class Command
 	protected
 
 		def catch_after(promise)
-			promise.catch_only(ErrorToSend) { |e|
+			promise.catch_only(FinalStanza) { |e|
 				@blather << e.stanza
 			}.catch do |e|
 				log_error(e)
-				finish(@format_error.call(e), type: :error)
+				finish(
+					@format_error.call(e), type: :error
+				).catch_only(FinalStanza) do |to_send|
+					@blather << to_send.stanza
+				end
 			end
 		end
 

lib/error_to_send.rb 🔗

@@ -1,10 +0,0 @@
-# frozen_string_literal: true
-
-class ErrorToSend < StandardError
-	attr_reader :stanza
-
-	def initialize(stanza)
-		super(stanza.to_s)
-		@stanza = stanza
-	end
-end

lib/registration.rb 🔗

@@ -8,7 +8,6 @@ require_relative "./alt_top_up_form"
 require_relative "./command"
 require_relative "./bandwidth_tn_order"
 require_relative "./em"
-require_relative "./error_to_send"
 require_relative "./oob"
 require_relative "./web_register_manager"
 

lib/web_register_manager.rb 🔗

@@ -1,7 +1,5 @@
 # frozen_string_literal: true
 
-require_relative "error_to_send"
-
 class WebRegisterManager
 	def initialize
 		@tel_map = Hash.new { ChooseTel.new }

sgx_jmp.rb 🔗

@@ -48,7 +48,6 @@ require_relative "lib/command_list"
 require_relative "lib/customer"
 require_relative "lib/customer_repo"
 require_relative "lib/electrum"
-require_relative "lib/error_to_send"
 require_relative "lib/em"
 require_relative "lib/payment_methods"
 require_relative "lib/registration"
@@ -388,7 +387,7 @@ Command.new(
 		Registration.for(customer, web_register_manager).then(&:write)
 	}.then {
 		StatsD.increment("registration.completed")
-	}.catch_only(ErrorToSend) do |e|
+	}.catch_only(Command::Execution::FinalStanza) do |e|
 		StatsD.increment("registration.completed")
 		EMPromise.reject(e)
 	end