From 1a127b0a52b7e73a1931f39d99bd444dc0b94ded Mon Sep 17 00:00:00 2001 From: Terje Karlsen Date: Sat, 7 Oct 2023 09:11:21 +0200 Subject: [PATCH] Wrap unleash in error --- src/server/api-handlers/features.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/server/api-handlers/features.ts b/src/server/api-handlers/features.ts index d5de7693d..13b20b673 100644 --- a/src/server/api-handlers/features.ts +++ b/src/server/api-handlers/features.ts @@ -9,13 +9,17 @@ const initializeUnleash = async () => { return false; } - unleashInstance = initialize({ - url: UNLEASH_SERVER_API_URL, - appName: 'nav-dekoratoren', - customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN }, - }); - - console.log(unleashInstance.isSynchronized() ? 'Unleash is synchronized' : 'Unleash is not synchronized'); + try { + unleashInstance = initialize({ + url: UNLEASH_SERVER_API_URL, + appName: 'nav-dekoratoren', + customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN }, + }); + + console.log(unleashInstance.isSynchronized() ? 'Unleash is synchronized' : 'Unleash is not synchronized'); + } catch (e) { + console.error('Error initializing unleash', e); + } return true; }; @@ -25,7 +29,7 @@ export const getFeaturesHandler: RequestHandler = async (req, res) => { // so just mock this. if (!unleashInstance) { - initializeUnleash(); + await initializeUnleash(); } // res.status(500).send('Missing UNLEASH_SERVER_API_TOKEN or UNLEASH_SERVER_API_URL');