From 51897c87b17d07e34eed71daf9e2d70ee1d48aa6 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 9 Jun 2021 13:02:38 -0500 Subject: [PATCH] Catch more exception in web-register command and send user to sentry --- sgx_jmp.rb | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 72e2cbc..39f2967 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -318,24 +318,30 @@ end command :execute?, node: "web-register", sessionid: nil do |iq| sentry_hub = new_sentry_hub(iq, name: iq.node) - jid = iq.form.field("jid")&.value.to_s.strip - tel = iq.form.field("tel")&.value.to_s.strip - if iq.from.stripped != CONFIG[:web_register][:from] - BLATHER << iq.as_error("forbidden", :auth) - elsif jid == "" || tel !~ /\A\+\d+\Z/ - reply_with_note(iq, "Invalid JID or telephone number.", type: :error) - else - IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd| - cmd.to = CONFIG[:web_register][:to] - cmd.from = CONFIG[:component][:jid] - cmd.node = "push-register" - cmd.form.fields = [var: "to", value: jid] - cmd.form.type = "submit" - }).then { |result| - final_jid = result.form.field("from")&.value.to_s.strip - web_register_manager[final_jid] = tel - BLATHER << iq.reply.tap { |reply| reply.status = :completed } - }.catch { |e| panic(e, sentry_hub) } + + begin + jid = iq.form.field("jid")&.value.to_s.strip + tel = iq.form.field("tel")&.value.to_s.strip + hub.current_scope.set_user(jid: jid, tel: tel) + if iq.from.stripped != CONFIG[:web_register][:from] + BLATHER << iq.as_error("forbidden", :auth) + elsif jid == "" || tel !~ /\A\+\d+\Z/ + reply_with_note(iq, "Invalid JID or telephone number.", type: :error) + else + IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd| + cmd.to = CONFIG[:web_register][:to] + cmd.from = CONFIG[:component][:jid] + cmd.node = "push-register" + cmd.form.fields = [var: "to", value: jid] + cmd.form.type = "submit" + }).then { |result| + final_jid = result.form.field("from")&.value.to_s.strip + web_register_manager[final_jid] = tel + BLATHER << iq.reply.tap { |reply| reply.status = :completed } + }.catch { |e| panic(e, sentry_hub) } + end + rescue StandardError => e + sentry_hub.capture_exception(e) end end -- 2.38.5