diff --git a/lib/command.rb b/lib/command.rb index 6ec7c1e052de2c9884df30e8d2254bc579edca15..b4ce5b9dce1c8bc2015bbff79436c0ad0ff6fba4 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 c9d3a9dfde79cf71fd7c95f1537955d689a18724..0000000000000000000000000000000000000000 --- 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 a2522ce559f10555e8748ce1f63aed4d73d94140..4c7425e77366f866038b951be1af15457fe1da66 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 7957355a40fd5a9793e5a5e4b2c0e5ca39f96f71..0a332c3f1afc2ba2b6a171e577397f178185ebf1 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 37e126915e73bcdc95711cca05f542565af52fe7..893a015082e1d73ebd86063603358546cf9650e2 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