From 444bba1eff2a5eb0abfc7bde4aa7b6fe7d9cacc9 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 29 Nov 2022 08:29:22 +0000 Subject: [PATCH 1/3] handle error in about card when refresh entity fails Signed-off-by: Brian Fletcher --- .../catalog/src/components/AboutCard/AboutCard.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index b7ccd49b31..7c0c8e69f7 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -139,8 +139,15 @@ export function AboutCard(props: AboutCardProps) { const allowRefresh = entityLocation?.startsWith('url:') || entityLocation?.startsWith('file:'); const refreshEntity = useCallback(async () => { - await catalogApi.refreshEntity(stringifyEntityRef(entity)); - alertApi.post({ message: 'Refresh scheduled', severity: 'info' }); + try { + await catalogApi.refreshEntity(stringifyEntityRef(entity)); + alertApi.post({ message: 'Refresh scheduled', severity: 'info' }); + } catch (e) { + alertApi.post({ + message: `Failed to schedule refresh: ${e.message}`, + severity: 'error', + }); + } }, [catalogApi, alertApi, entity]); return ( From ca04d97b0926d20c2299750ead809ed13dbcbad9 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 29 Nov 2022 08:33:15 +0000 Subject: [PATCH 2/3] add changelog Signed-off-by: Brian Fletcher --- .changeset/four-buttons-clean.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/four-buttons-clean.md diff --git a/.changeset/four-buttons-clean.md b/.changeset/four-buttons-clean.md new file mode 100644 index 0000000000..41af42b45e --- /dev/null +++ b/.changeset/four-buttons-clean.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Handle refresh entity error in `AboutCard`. From da8512789b84a7990b45b16e83915c753693cd85 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 29 Nov 2022 09:01:03 +0000 Subject: [PATCH 3/3] use errorApi Signed-off-by: Brian Fletcher --- .../src/components/AboutCard/AboutCard.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index 7c0c8e69f7..cb48be2b26 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -26,7 +26,12 @@ import { InfoCardVariants, Link, } from '@backstage/core-components'; -import { alertApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api'; +import { + alertApiRef, + errorApiRef, + useApi, + useRouteRef, +} from '@backstage/core-plugin-api'; import { ScmIntegrationIcon, scmIntegrationsApiRef, @@ -90,6 +95,7 @@ export function AboutCard(props: AboutCardProps) { const scmIntegrationsApi = useApi(scmIntegrationsApiRef); const catalogApi = useApi(catalogApiRef); const alertApi = useApi(alertApiRef); + const errorApi = useApi(errorApiRef); const viewTechdocLink = useRouteRef(viewTechDocRouteRef); const entitySourceLocation = getEntitySourceLocation( @@ -143,12 +149,9 @@ export function AboutCard(props: AboutCardProps) { await catalogApi.refreshEntity(stringifyEntityRef(entity)); alertApi.post({ message: 'Refresh scheduled', severity: 'info' }); } catch (e) { - alertApi.post({ - message: `Failed to schedule refresh: ${e.message}`, - severity: 'error', - }); + errorApi.post(e); } - }, [catalogApi, alertApi, entity]); + }, [catalogApi, alertApi, errorApi, entity]); return (