Skip to content

Commit

Permalink
Log invalid featuretoggle name (#6472)
Browse files Browse the repository at this point in the history
* Log invalid featuretoggle name

* bedre namiing
  • Loading branch information
sebassonav authored Nov 27, 2024
1 parent ecee335 commit d0fd478
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppSwitcher } from '~shared/header/AppSwitcher'

export const HeaderBanner = () => {
const innloggetSaksbehandler = useInnloggetSaksbehandler()

return (
<InternalHeader data-theme="light">
<InternalHeader.Title href="/">Gjenny</InternalHeader.Title>
Expand Down
21 changes: 17 additions & 4 deletions apps/etterlatte-saksbehandling-ui/client/src/useUnleash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -87,8 +88,10 @@ export const unleashStartState: Record<string, Toggle> = {

export const Unleashcontext = createContext<{
updateToggle: () => void
logWithThrottle: (featureToggle: FeatureToggle) => void
}>({
updateToggle: () => {},
logWithThrottle: () => {},
})

const mapStatusForToggle = (featureToggle: IFeature, defaultValue: boolean): boolean => {
Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit d0fd478

Please sign in to comment.