From d0fd4788e7cd42c4be0cd3ca560a21deb81318b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Oliver=20S=C3=B8berg?= <82504565+sebassonav@users.noreply.github.com> Date: Wed, 27 Nov 2024 22:38:06 +0100 Subject: [PATCH] Log invalid featuretoggle name (#6472) * Log invalid featuretoggle name * bedre namiing --- .../client/src/shared/header/HeaderBanner.tsx | 1 + .../client/src/useUnleash.ts | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/etterlatte-saksbehandling-ui/client/src/shared/header/HeaderBanner.tsx b/apps/etterlatte-saksbehandling-ui/client/src/shared/header/HeaderBanner.tsx index 8e752e72916..a5b2e8a8736 100644 --- a/apps/etterlatte-saksbehandling-ui/client/src/shared/header/HeaderBanner.tsx +++ b/apps/etterlatte-saksbehandling-ui/client/src/shared/header/HeaderBanner.tsx @@ -6,6 +6,7 @@ import { AppSwitcher } from '~shared/header/AppSwitcher' export const HeaderBanner = () => { const innloggetSaksbehandler = useInnloggetSaksbehandler() + return ( Gjenny diff --git a/apps/etterlatte-saksbehandling-ui/client/src/useUnleash.ts b/apps/etterlatte-saksbehandling-ui/client/src/useUnleash.ts index fe20dad7ffe..fd6bded1a73 100644 --- a/apps/etterlatte-saksbehandling-ui/client/src/useUnleash.ts +++ b/apps/etterlatte-saksbehandling-ui/client/src/useUnleash.ts @@ -5,6 +5,7 @@ import { hentFeatureToggles } from '~shared/api/unleash' import { useDispatch } from 'react-redux' import { endreToggle, useUnleashReducer, useUnleashReducerToggle } from '~store/reducers/UnleashReducer' import { throttle } from 'lodash' +import { logger } from '~utils/logger' export const enum FeatureToggle { sanksjon = 'sanksjon', @@ -87,8 +88,10 @@ export const unleashStartState: Record = { export const Unleashcontext = createContext<{ updateToggle: () => void + logWithThrottle: (featureToggle: FeatureToggle) => void }>({ updateToggle: () => {}, + logWithThrottle: () => {}, }) const mapStatusForToggle = (featureToggle: IFeature, defaultValue: boolean): boolean => { @@ -104,6 +107,12 @@ const mapStatusForToggle = (featureToggle: IFeature, defaultValue: boolean): boo } } +const logMissingFeatureToggle = (featureToggle: FeatureToggle) => { + const msg = `Ugyldig toggle registrert: ${featureToggle}` + console.error(msg) + logger.generalError({ msg: msg }) +} + export const useUnleash = () => { const dispatch = useDispatch() const [, fetchFeature] = useApiCall(hentFeatureToggles) @@ -125,16 +134,20 @@ export const useUnleash = () => { ) } - return { updateToggle: throttle(updateToggle, 1000) } + return { updateToggle: throttle(updateToggle, 1000), logWithThrottle: throttle(logMissingFeatureToggle, 1000) } } export const useFeaturetoggle = (featureToggle: FeatureToggle): boolean => { - const { updateToggle } = useContext(Unleashcontext) + const { updateToggle, logWithThrottle } = useContext(Unleashcontext) const toggle = useUnleashReducerToggle(featureToggle) useEffect(() => { - updateToggle() + if (toggle) { + updateToggle() + } else { + logWithThrottle(featureToggle) + } }, []) - return toggle.enabled + return toggle ? toggle.enabled : false }