Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Handle error on detector detail pages #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions public/pages/DetectorDetail/containers/DetectorDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ interface DetectorDetailModel {
export const DetectorDetail = (props: DetectorDetailProps) => {
const dispatch = useDispatch();
const detectorId = get(props, 'match.params.detectorId', '') as string;
const { detector, hasError, isLoadingDetector } = useFetchDetectorInfo(detectorId);
const { monitor, fetchMonitorError, isLoadingMonitor } = useFetchMonitorInfo(detectorId);
const { detector, hasError, isLoadingDetector } = useFetchDetectorInfo(
detectorId
);
const { monitor, fetchMonitorError, isLoadingMonitor } = useFetchMonitorInfo(
detectorId
);

//TODO: test dark mode once detector configuration and AD result page merged
const isDark = darkModeEnabled();
Expand Down Expand Up @@ -266,7 +270,10 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
: { ...lightStyles, flexGrow: 'unset' }),
}}
>
<EuiFlexGroup justifyContent="spaceBetween" style={{ padding: '10px' }}>
<EuiFlexGroup
justifyContent="spaceBetween"
style={{ padding: '10px' }}
>
<EuiFlexItem grow={false}>
<EuiTitle size="l">
<h1>
Expand All @@ -282,19 +289,29 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
</EuiHealth>
) : detector.enabled &&
detector.curState === DETECTOR_STATE.INIT ? (
<EuiHealth color={DETECTOR_STATE_COLOR.INIT}>Initializing</EuiHealth>
<EuiHealth color={DETECTOR_STATE_COLOR.INIT}>
Initializing
</EuiHealth>
) : detector.curState === DETECTOR_STATE.INIT_FAILURE ||
detector.curState === DETECTOR_STATE.UNEXPECTED_FAILURE ? (
<EuiHealth color={DETECTOR_STATE_COLOR.INIT_FAILURE}>Initialization failure</EuiHealth>
<EuiHealth color={DETECTOR_STATE_COLOR.INIT_FAILURE}>
Initialization failure
</EuiHealth>
) : detector.curState === DETECTOR_STATE.DISABLED ? (
<EuiHealth color={DETECTOR_STATE_COLOR.DISABLED}>
{detector.disabledTime
? `Stopped at ${moment(detector.disabledTime).format('MM/DD/YY h:mm A')}`
: 'Detector is stopped'}
? `Stopped at ${moment(detector.disabledTime).format(
'MM/DD/YY h:mm A'
)}`
: 'Detector is stopped'}
</EuiHealth>
) : detector.curState === DETECTOR_STATE.FEATURE_REQUIRED ? (
<EuiHealth color={DETECTOR_STATE_COLOR.FEATURE_REQUIRED}>Feature required to start the detector</EuiHealth>
) : ''}
<EuiHealth color={DETECTOR_STATE_COLOR.FEATURE_REQUIRED}>
Feature required to start the detector
</EuiHealth>
) : (
''
)}
</h1>
</EuiTitle>
</EuiFlexItem>
Expand Down
9 changes: 5 additions & 4 deletions public/redux/reducers/__tests__/ad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe('detector reducer actions', () => {
});
test('should invoke [REQUEST, FAILURE]', async () => {
const detectorId = 'randomDetectorID';
httpMockedClient.get = jest
.fn()
.mockRejectedValue({ data: { ok: false, error: 'Not found' } });
httpMockedClient.get = jest.fn().mockRejectedValue('Not found');
try {
await store.dispatch(getDetector(detectorId));
} catch (e) {
Expand Down Expand Up @@ -206,7 +204,10 @@ describe('detector reducer actions', () => {
[detectorId]: {
...randomDetector,
id: detectorId,
lastUpdateTime: get(result, `detectors.${detectorId}.lastUpdateTime`)
lastUpdateTime: get(
result,
`detectors.${detectorId}.lastUpdateTime`
),
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion public/redux/reducers/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const reducer = handleActions<Detectors>(
FAILURE: (state: Detectors, action: APIErrorAction): Detectors => ({
...state,
requesting: false,
errorMessage: action.error.data.error,
errorMessage: action.error,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line here was causing an exception. data was undefined, which caused the error to be thrown. Because of this, the ad state never got out of requesting and was preventing the detector details pages from handling the error and redirecting to the detector list page.

}),
},
[START_DETECTOR]: {
Expand Down