Catch catalog errors

This commit is contained in:
Adam Harvey
2021-02-09 12:53:21 -05:00
parent 793c334913
commit 1cd0e07f7b
2 changed files with 21 additions and 2 deletions
@@ -90,4 +90,17 @@ describe('<DomainExplorerContent />', () => {
expect(getByText('No domains to display')).toBeInTheDocument(),
);
});
it('renders a friendly error if it cannot collect domains', async () => {
const catalogError = new Error('Network timeout');
catalogApi.getEntities.mockRejectedValueOnce(catalogError);
const { getByText } = render(<DomainExplorerContent />, {
wrapper: Wrapper,
});
await waitFor(() =>
expect(getByText(/Could not load domains/)).toBeInTheDocument(),
);
});
});
@@ -21,6 +21,7 @@ import {
Progress,
SupportButton,
useApi,
WarningPanel,
} from '@backstage/core';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { Button } from '@material-ui/core';
@@ -30,7 +31,7 @@ import { DomainCardGrid } from '../DomainCard';
export const DomainExplorerContent = () => {
const catalogApi = useApi(catalogApiRef);
const { value: entities, loading } = useAsync(async () => {
const { value: entities, loading, error } = useAsync(async () => {
const response = await catalogApi.getEntities({
filter: { kind: 'domain' },
});
@@ -45,7 +46,12 @@ export const DomainExplorerContent = () => {
</ContentHeader>
{loading && <Progress />}
{!loading && (!entities || entities.length === 0) && (
{error && (
<WarningPanel severity="error" title="Could not load domains.">
{error.message}
</WarningPanel>
)}
{!loading && !error && (!entities || entities.length === 0) && (
<EmptyState
missing="info"
title="No domains to display"