From 8eb950ff649b18430d29364ff0a11a5593e1515d Mon Sep 17 00:00:00 2001 From: Owen Shartle Date: Mon, 25 Aug 2025 21:36:57 -0400 Subject: [PATCH] Adding a try-catch around the usage of the catalog API in the TechDocsReaderPage as it could still attempt to load a standard TechDocs page. Signed-off-by: Owen Shartle --- .../TechDocsReaderPage.test.tsx | 25 +++++++++++++++++++ .../TechDocsReaderPage/TechDocsReaderPage.tsx | 12 ++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.test.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.test.tsx index 93f24e9f97..c645d1db83 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.test.tsx @@ -413,5 +413,30 @@ describe('', () => { expect(rendered.container.querySelector('article')).toBeInTheDocument(); expect(mockNavigate).not.toHaveBeenCalled(); }); + + it('should render normally when catalog API throws an error', async () => { + catalogApiMock.getEntityByRef.mockRejectedValue( + new Error('Catalog API error'), + ); + + const rendered = await renderInTestApp( + + + , + { + mountedRoutes, + }, + ); + + expect(rendered.container.querySelector('header')).toBeInTheDocument(); + expect(rendered.container.querySelector('article')).toBeInTheDocument(); + expect(mockNavigate).not.toHaveBeenCalled(); + }); }); }); diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.tsx index 9b4999899d..c67660fd79 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPage/TechDocsReaderPage.tsx @@ -215,10 +215,16 @@ export const TechDocsReaderPage = (props: TechDocsReaderPageProps) => { ); const externalEntityTechDocsUrl = useAsync(async () => { - const catalogEntity = await catalogApi.getEntityByRef(memoizedEntityRef); + try { + const catalogEntity = await catalogApi.getEntityByRef(memoizedEntityRef); - if (catalogEntity?.metadata?.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION]) { - return buildTechDocsURL(catalogEntity, viewTechdocLink); + if ( + catalogEntity?.metadata?.annotations?.[TECHDOCS_EXTERNAL_ANNOTATION] + ) { + return buildTechDocsURL(catalogEntity, viewTechdocLink); + } + } catch (error) { + // Ignore error and allow an attempt at loading the current entity's TechDocs when unable to fetch an external entity from the catalog. } return undefined;