From 1cd0e07f7b94125722bd4ff5ebd22d9cea90bf87 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 9 Feb 2021 12:53:21 -0500 Subject: [PATCH] Catch catalog errors --- .../DomainExplorerContent.test.tsx | 13 +++++++++++++ .../DomainExplorerContent/DomainExplorerContent.tsx | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx index 4846565bdd..a52b0d8f2c 100644 --- a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx +++ b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx @@ -90,4 +90,17 @@ describe('', () => { 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(, { + wrapper: Wrapper, + }); + + await waitFor(() => + expect(getByText(/Could not load domains/)).toBeInTheDocument(), + ); + }); }); diff --git a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.tsx b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.tsx index ca00c525c9..182adf70ea 100644 --- a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.tsx +++ b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.tsx @@ -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 = () => { {loading && } - {!loading && (!entities || entities.length === 0) && ( + {error && ( + + {error.message} + + )} + {!loading && !error && (!entities || entities.length === 0) && (