Skip to content

Commit

Permalink
Handle api errors on event filters and trusted apps summary api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dasansol92 committed May 27, 2021
1 parent 5b17fd5 commit 39c8133
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getEventFiltersListPath } from '../../../../../../common/routing';
import { GetExceptionSummaryResponse } from '../../../../../../../../common/endpoint/types';
import { PLUGIN_ID as FLEET_PLUGIN_ID } from '../../../../../../../../../fleet/common';
import { MANAGEMENT_APP_ID } from '../../../../../../common/constants';
import { useToasts } from '../../../../../../../common/lib/kibana';
import { LinkWithIcon } from './link_with_icon';
import { ExceptionItemsSummary } from './exception_items_summary';
import { EventFiltersHttpService } from '../../../../../event_filters/service';
Expand All @@ -30,18 +31,29 @@ export const FleetEventFiltersCard = memo<PackageCustomExtensionComponentProps>(
http,
},
} = useKibana<CoreStart & { application: ApplicationStart }>();

const toasts = useToasts();
const [stats, setStats] = useState<GetExceptionSummaryResponse | undefined>();
const eventFiltersListUrlPath = getEventFiltersListPath();
const eventFiltersApi = useMemo(() => new EventFiltersHttpService(http), [http]);

useEffect(() => {
const fetchStats = async () => {
const summary = await eventFiltersApi.getSummary();
setStats(summary);
try {
const summary = await eventFiltersApi.getSummary();
setStats(summary);
} catch (err) {
toasts.addDanger(
i18n.translate(
'xpack.securitySolution.endpoint.fleetCustomExtension.eventFiltersSummaryError',
{
defaultMessage: 'There was an error trying to fetch event filters stats',
}
)
);
}
};
fetchStats();
}, [eventFiltersApi]);
}, [eventFiltersApi, toasts]);

const eventFiltersRouteState = useMemo(() => {
const fleetPackageCustomUrlPath = `#${pagePathGetters.integration_details_custom({ pkgkey })}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../../../../../../../common/endpoint/types';
import { PLUGIN_ID as FLEET_PLUGIN_ID } from '../../../../../../../../../fleet/common';
import { MANAGEMENT_APP_ID } from '../../../../../../common/constants';
import { useToasts } from '../../../../../../../common/lib/kibana';
import { LinkWithIcon } from './link_with_icon';
import { ExceptionItemsSummary } from './exception_items_summary';
import { TrustedAppsHttpService } from '../../../../../trusted_apps/service';
Expand All @@ -33,15 +34,28 @@ export const FleetTrustedAppsCard = memo<PackageCustomExtensionComponentProps>((
http,
},
} = useKibana<CoreStart & { application: ApplicationStart }>();

const toasts = useToasts();
const [stats, setStats] = useState<GetExceptionSummaryResponse | undefined>();
const trustedAppsApi = useMemo(() => new TrustedAppsHttpService(http), [http]);

useEffect(() => {
trustedAppsApi.getTrustedAppsSummary().then((response) => {
setStats(response);
});
}, [trustedAppsApi]);
const fetchStats = async () => {
try {
const response = await trustedAppsApi.getTrustedAppsSummary();
setStats(response);
} catch (err) {
toasts.addDanger(
i18n.translate(
'xpack.securitySolution.endpoint.fleetCustomExtension.eventFiltersSummaryError',
{
defaultMessage: 'There was an error trying to fetch trusted apps stats',
}
)
);
}
};
fetchStats();
}, [toasts, trustedAppsApi]);
const trustedAppsListUrlPath = getTrustedAppsListPath();

const trustedAppRouteState = useMemo<TrustedAppsListPageRouteState>(() => {
Expand Down

0 comments on commit 39c8133

Please sign in to comment.