~singpolyma/sgx-jmp

7f5da6b61064fd3b0b7c80161d60a5ba8e96b504 — Stephen Paul Weber 11 months ago 4c37bad + 46b3f4f
Merge branch 'customer-not-found'

* customer-not-found:
  Customer not found, return auth error instead of panic
  Catchable CustomerRepo::NotFound
2 files changed, 9 insertions(+), 7 deletions(-)

M lib/customer_repo.rb
M sgx_jmp.rb
M lib/customer_repo.rb => lib/customer_repo.rb +7 -7
@@ 7,6 7,8 @@ require_relative "legacy_customer"
require_relative "polyfill"

class CustomerRepo
	class NotFound < RuntimeError; end

	def initialize(
		redis: LazyObject.new { REDIS },
		db: LazyObject.new { DB },


@@ 21,7 23,7 @@ class CustomerRepo

	def find(customer_id)
		@redis.get("jmp_customer_jid-#{customer_id}").then do |jid|
			raise "No jid" unless jid
			raise NotFound, "No jid" unless jid
			find_inner(customer_id, jid)
		end
	end


@@ 30,18 32,16 @@ class CustomerRepo
		if jid.to_s =~ /\Acustomer_(.+)@#{CONFIG[:component][:jid]}\Z/
			find($1)
		else
			@redis.get("jmp_customer_id-#{jid}").then { |customer_id|
				raise "No customer id" unless customer_id
			@redis.get("jmp_customer_id-#{jid}").then do |customer_id|
				next find_legacy_customer(jid) unless customer_id
				find_inner(customer_id, jid)
			}.catch do
				find_legacy_customer(jid)
			end
		end
	end

	def find_by_tel(tel)
		@redis.get("catapult_jid-#{tel}").then do |jid|
			raise "No jid" unless jid
			raise NotFound, "No jid" unless jid
			find_by_jid(jid)
		end
	end


@@ 69,7 69,7 @@ protected

	def find_legacy_customer(jid)
		@redis.lindex("catapult_cred-#{jid}", 3).then do |tel|
			raise "No customer" unless tel
			raise NotFound, "No customer" unless tel
			LegacyCustomer.new(Blather::JID.new(jid), tel)
		end
	end

M sgx_jmp.rb => sgx_jmp.rb +2 -0
@@ 269,6 269,8 @@ message(
		m.to = m.to.with(domain: customer.jid.domain)
		address["jid"] = customer.jid.to_s
		BLATHER << m
	}.catch_only(CustomerRepo::NotFound) { |e|
		BLATHER << iq.as_error("forbidden", :auth, e.message)
	}.catch { |e| panic(e, sentry_hub) }
end