From a10d807e733b00abdfa5c54909677c26955ad713 Mon Sep 17 00:00:00 2001 From: Benjamin Chrobot Date: Sun, 10 Dec 2023 09:46:34 -0500 Subject: [PATCH] fix: handle spoke-portal being unreachable --- .../lib/notices/register-10dlc-brand.ts | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/server/lib/notices/register-10dlc-brand.ts b/src/server/lib/notices/register-10dlc-brand.ts index f0facf451..177ddc3cd 100644 --- a/src/server/lib/notices/register-10dlc-brand.ts +++ b/src/server/lib/notices/register-10dlc-brand.ts @@ -72,20 +72,30 @@ export const get10DlcBrandNotices: OrgLevelNotificationGetter = async ( const ownedProfiles = profiles.filter(({ roles }) => roles.includes("OWNER")); - const profilesWithChannels = await Promise.all( - profiles.map(async ({ messaging_service_sid }) => { - const payload = { - operationName: "GetSwitchboardProfile", - query: fetchProfileQuery, - variables: { - profileId: messaging_service_sid - } - }; - - const profileResponse = await request.post(PORTAL_API_URL).send(payload); - return profileResponse.body.data?.profile; - }) - ); + let profilesWithChannels: any[] = []; + try { + profilesWithChannels = await Promise.all( + profiles.map(async ({ messaging_service_sid }) => { + const payload = { + operationName: "GetSwitchboardProfile", + query: fetchProfileQuery, + variables: { + profileId: messaging_service_sid + } + }; + + const profileResponse = await request + .post(PORTAL_API_URL) + .timeout(1000) + .send(payload); + + return profileResponse.body.data?.profile; + }) + ); + } catch { + // Error fetching from Portal (it may not be reachable) + return []; + } // if a registered profile exists, show the notice for their lowest cost pricing plan