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 <timeloveinvent+github@gmail.com>
This commit is contained in:
Owen Shartle
2025-08-25 21:36:57 -04:00
parent 40fe543447
commit 8eb950ff64
2 changed files with 34 additions and 3 deletions
@@ -413,5 +413,30 @@ describe('<TechDocsReaderPage />', () => {
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(
<Wrapper>
<TechDocsReaderPage
entityRef={{
name: 'test-name',
namespace: 'test-namespace',
kind: 'test-kind',
}}
/>
</Wrapper>,
{
mountedRoutes,
},
);
expect(rendered.container.querySelector('header')).toBeInTheDocument();
expect(rendered.container.querySelector('article')).toBeInTheDocument();
expect(mockNavigate).not.toHaveBeenCalled();
});
});
});
@@ -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;