diff --git a/projects/plugins/protect/src/js/hooks/use-fixers.ts b/projects/plugins/protect/src/js/hooks/use-fixers.ts index 2d31b65bb35cf..d86fd4e66a23c 100644 --- a/projects/plugins/protect/src/js/hooks/use-fixers.ts +++ b/projects/plugins/protect/src/js/hooks/use-fixers.ts @@ -13,7 +13,11 @@ export const fixerTimestampIsStale = ( lastUpdatedTimestamp: string ) => { }; export const fixerStatusIsStale = ( fixerStatus: ThreatFixStatus ) => { - return fixerStatus.status === 'in_progress' && fixerTimestampIsStale( fixerStatus.last_updated ); + return ( + 'status' in fixerStatus && + fixerStatus.status === 'in_progress' && + fixerTimestampIsStale( fixerStatus.last_updated ) + ); }; type UseFixersResult = { @@ -40,13 +44,20 @@ export default function useFixers(): UseFixersResult { const isThreatFixInProgress = useCallback( ( threatId: number ) => { - return fixersStatus?.threats?.[ threatId ]?.status === 'in_progress'; + if ( fixersStatus.ok === false ) { + return false; + } + const threatFix = fixersStatus.threats?.[ threatId ]; + return 'status' in threatFix && threatFix.status === 'in_progress'; }, [ fixersStatus ] ); const isThreatFixStale = useCallback( ( threatId: number ) => { + if ( fixersStatus.ok === false ) { + return false; + } const threatFixStatus = fixersStatus?.threats?.[ threatId ]; return threatFixStatus ? fixerStatusIsStale( threatFixStatus ) : false; }, diff --git a/projects/plugins/protect/src/js/types/fixers.ts b/projects/plugins/protect/src/js/types/fixers.ts index 519b3344b8eba..6f5cd693eb999 100644 --- a/projects/plugins/protect/src/js/types/fixers.ts +++ b/projects/plugins/protect/src/js/types/fixers.ts @@ -38,3 +38,5 @@ export type ThreatFixStatusSuccess = { status: FixerStatus; // Threat fix status (one of 'not_started', 'in_progress', etc.) last_updated: string; // Last updated timestamp }; + +export type ThreatFixStatus = ThreatFixError | ThreatFixStatusSuccess;