From 9444afcdf27ade8182b203aa1fc9eb95a622ea95 Mon Sep 17 00:00:00 2001 From: Terje Karlsen Date: Fri, 6 Oct 2023 12:50:45 +0200 Subject: [PATCH] Wrap unleash-klient inn i try catch --- src/server/api-handlers/features.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/server/api-handlers/features.ts b/src/server/api-handlers/features.ts index 6d592ef7b..e5c1f5c53 100644 --- a/src/server/api-handlers/features.ts +++ b/src/server/api-handlers/features.ts @@ -20,14 +20,19 @@ export const getFeaturesHandler: RequestHandler = async (req, res) => { return; } - const unleash = await startUnleash({ - url: UNLEASH_SERVER_API_URL, - appName: 'nav-dekoratoren', - customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN }, - }); + try { + const unleash = await startUnleash({ + url: UNLEASH_SERVER_API_URL, + appName: 'nav-dekoratoren', + customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN }, + }); - return { - skjermdeling: unleash.isEnabled('dekoratoren.skjermdeling'), - chatbotscript: unleash.isEnabled('dekoratoren.chatbotscript'), - }; + return { + skjermdeling: unleash.isEnabled('dekoratoren.skjermdeling'), + chatbotscript: unleash.isEnabled('dekoratoren.chatbotscript'), + }; + } catch (e) { + console.error(`Failed to fetch feature toggles from unleash - ${e}`); + res.status(500).send(`Failed to fetch feature toggles from unleash - ${e}`); + } };