From 41807e87b305019eb6380690160c08ee25d3b940 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 31 Oct 2024 08:44:36 +0000 Subject: [PATCH] Don't throw if no account-holder is found --- .../src/api/controllers/global/users.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index 52f8821fab0..fa19948bf5e 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -312,16 +312,21 @@ export const tenantUserLookup = async (ctx: any) => { * So the account holder may not be found until further pagination has occurred */ export const accountHolderLookup = async (ctx: Ctx) => { - const users = await userSdk.core.getAllUsers() - const response = await userSdk.core.getExistingAccounts( - users.map(u => u.email) - ) - const holder = response[0] - if (!holder) { - return + try { + const users = await userSdk.core.getAllUsers() + const response = await userSdk.core.getExistingAccounts( + users.map(u => u.email) + ) + const holder = response[0] + if (!holder) { + ctx.body = null + return + } + holder._id = users.find(u => u.email === holder.email)?._id + ctx.body = holder + } catch (e) { + ctx.body = null } - holder._id = users.find(u => u.email === holder.email)?._id - ctx.body = holder } /*