Check error state more reliably

pull/87052/head^2
Tom Ratcliffe 2 years ago committed by Tom Ratcliffe
parent a0373c66c3
commit 4fb1ac2bec
  1. 4
      .betterer.results
  2. 9
      public/app/features/alerting/unified/components/silences/SilencesTable.tsx

@ -2158,10 +2158,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Styles should be written using objects.", "3"], [0, 0, 0, "Styles should be written using objects.", "3"],
[0, 0, 0, "Styles should be written using objects.", "4"] [0, 0, 0, "Styles should be written using objects.", "4"]
], ],
"public/app/features/alerting/unified/components/silences/SilencesTable.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
],
"public/app/features/alerting/unified/hooks/useAlertmanagerConfig.ts:5381": [ "public/app/features/alerting/unified/hooks/useAlertmanagerConfig.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"] [0, 0, 0, "Do not use any type assertions.", "0"]
], ],

@ -2,6 +2,7 @@ import { css } from '@emotion/css';
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { dateMath, GrafanaTheme2 } from '@grafana/data'; import { dateMath, GrafanaTheme2 } from '@grafana/data';
import { isFetchError } from '@grafana/runtime';
import { CollapsableSection, Icon, Link, LinkButton, useStyles2, Stack, Alert } from '@grafana/ui'; import { CollapsableSection, Icon, Link, LinkButton, useStyles2, Stack, Alert } from '@grafana/ui';
import { useQueryParams } from 'app/core/hooks/useQueryParams'; import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { alertSilencesApi } from 'app/features/alerting/unified/api/alertSilencesApi'; import { alertSilencesApi } from 'app/features/alerting/unified/api/alertSilencesApi';
@ -59,8 +60,7 @@ const SilencesTable = ({ alertManagerSourceName }: Props) => {
); );
const mimirLazyInitError = const mimirLazyInitError =
// eslint-disable-next-line @typescript-eslint/no-explicit-any isFetchError(error) && error?.message?.includes('the Alertmanager is not configured') && amFeatures?.lazyConfigInit;
(error as any)?.message?.includes('the Alertmanager is not configured') && amFeatures?.lazyConfigInit;
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
const [queryParams] = useQueryParams(); const [queryParams] = useQueryParams();
@ -109,9 +109,8 @@ const SilencesTable = ({ alertManagerSourceName }: Props) => {
); );
} }
if (error) { if (isFetchError(error)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any const errMessage = error?.message || 'Unknown error.';
const errMessage = (error as any)?.message || 'Unknown error.';
return ( return (
<Alert severity="error" title="Error loading silences"> <Alert severity="error" title="Error loading silences">
{errMessage} {errMessage}

Loading…
Cancel
Save