From d1a28bd8a2c1f2d064523bcf07407f64e48d443c Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 10 Aug 2021 10:11:13 -0500 Subject: [PATCH] ErrorToSend => FinalStanza --- 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(-) delete mode 100644 lib/error_to_send.rb diff --git a/lib/command.rb b/lib/command.rb index 6ec7c1e..b4ce5b9 100644 --- a/lib/command.rb +++ b/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 diff --git a/lib/error_to_send.rb b/lib/error_to_send.rb deleted file mode 100644 index c9d3a9d..0000000 --- a/lib/error_to_send.rb +++ /dev/null @@ -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 diff --git a/lib/registration.rb b/lib/registration.rb index a2522ce..4c7425e 100644 --- a/lib/registration.rb +++ b/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" diff --git a/lib/web_register_manager.rb b/lib/web_register_manager.rb index 7957355..0a332c3 100644 --- a/lib/web_register_manager.rb +++ b/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 } diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 37e1269..893a015 100644 --- a/sgx_jmp.rb +++ b/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 -- 2.45.2