mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 15:35:57 +08:00
Merge pull request #1126 from palash-signoz/alerts-rules-error-handling
fix: list alerts rules is handled
This commit is contained in:
commit
8e360e001f
@ -1,6 +1,7 @@
|
|||||||
|
import { notification } from 'antd';
|
||||||
import getAll from 'api/alerts/getAll';
|
import getAll from 'api/alerts/getAll';
|
||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
|
|
||||||
@ -8,15 +9,37 @@ import ListAlert from './ListAlert';
|
|||||||
|
|
||||||
function ListAlertRules(): JSX.Element {
|
function ListAlertRules(): JSX.Element {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { data, isError, isLoading, refetch } = useQuery('allAlerts', {
|
const { data, isError, isLoading, refetch, status } = useQuery('allAlerts', {
|
||||||
queryFn: getAll,
|
queryFn: getAll,
|
||||||
cacheTime: 0,
|
cacheTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === 'error' || (status === 'success' && data.statusCode >= 400)) {
|
||||||
|
notification.error({
|
||||||
|
message: data?.error || t('something_went_wrong'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [data?.error, data?.statusCode, status, t]);
|
||||||
|
|
||||||
|
// api failed to load the data
|
||||||
if (isError) {
|
if (isError) {
|
||||||
return <div>{data?.error || t('something_went_wrong')}</div>;
|
return <div>{data?.error || t('something_went_wrong')}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// api is successful but error is present
|
||||||
|
if (status === 'success' && data.statusCode >= 400) {
|
||||||
|
return (
|
||||||
|
<ListAlert
|
||||||
|
{...{
|
||||||
|
allAlertRules: [],
|
||||||
|
refetch,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case of loading
|
||||||
if (isLoading || !data?.payload) {
|
if (isLoading || !data?.payload) {
|
||||||
return <Spinner height="75vh" tip="Loading Rules..." />;
|
return <Spinner height="75vh" tip="Loading Rules..." />;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user