~singpolyma/sgx-jmp

51897c87b17d07e34eed71daf9e2d70ee1d48aa6 — Stephen Paul Weber 9 days ago c9a8aa5
Catch more exception in web-register command and send user to sentry
1 files changed, 24 insertions(+), 18 deletions(-)

M sgx_jmp.rb
M sgx_jmp.rb => sgx_jmp.rb +24 -18
@@ 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