On customer load error, try not loading from SGX and assuming no transcription

Stephen Paul Weber created

Change summary

lib/trivial_backend_sgx_repo.rb |  6 ++++--
web.rb                          | 18 +++++++++++++++---
2 files changed, 19 insertions(+), 5 deletions(-)

Detailed changes

lib/trivial_backend_sgx_repo.rb 🔗

@@ -7,11 +7,13 @@ class TrivialBackendSgxRepo
 	def initialize(
 		jid: CONFIG[:sgx],
 		creds: CONFIG[:creds],
-		component_jid: CONFIG[:component][:jid]
+		component_jid: CONFIG[:component][:jid],
+		**with
 	)
 		@jid = Blather::JID.new(jid)
 		@creds = creds
 		@component_jid = component_jid
+		@with = with
 	end
 
 	def get(customer_id)
@@ -22,6 +24,6 @@ class TrivialBackendSgxRepo
 			fwd: NotLoaded.new(:fwd_timeout),
 			transcription_enabled: NotLoaded.new(:transcription_enabled),
 			registered?: NotLoaded.new(:registered?)
-		)
+		).with(@with)
 	end
 end

web.rb 🔗

@@ -106,6 +106,17 @@ class Web < Roda
 		opts[:customer_repo] || CustomerRepo.new(**kwargs)
 	end
 
+	def find_by_tel_with_fallback(sgx_repo:, **kwargs)
+		customer_repo(sgx_repo: sgx_repo).find_by_tel(params["to"]).catch { |e|
+			next EMPromise.reject(e) if e.is_a?(CustomerRepo::NotFound)
+
+			log_error(e)
+			customer_repo(
+				sgx_repo: TrivialBackendSgxRepo.new(**kwargs)
+			).find_by_tel(params["to"])
+		}
+	end
+
 	def call_attempt_repo
 		opts[:call_attempt_repo] || CallAttemptRepo.new
 	end
@@ -223,9 +234,10 @@ class Web < Roda
 								"https://jmp.chat"
 							)
 
-							customer_repo(
-								sgx_repo: Bwmsgsv2Repo.new
-							).find_by_tel(params["to"]).then do |customer|
+							find_by_tel_with_fallback(
+								sgx_repo: Bwmsgsv2Repo.new,
+								transcription_enabled: false
+							).then do |customer|
 								start_transcription(customer, call_id, jmp_media_url)
 
 								m = Blather::Stanza::Message.new