From b78e3fdb718f865f71c8a06d2874ec52a433f7cc Mon Sep 17 00:00:00 2001 From: Alex Lorenzi Date: Wed, 12 Feb 2025 15:45:10 -0500 Subject: [PATCH] When the catalog entity couldn't be found the /sync endpoint would return with a 404 and a JSON response which was not expected by the event-stream fetch on the frontend. This causes the client to continuously make requests to the /sync endpoint. Signed-off-by: Alex Lorenzi --- .changeset/good-flowers-promise.md | 5 +++++ plugins/techdocs-backend/src/service/router.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/good-flowers-promise.md diff --git a/.changeset/good-flowers-promise.md b/.changeset/good-flowers-promise.md new file mode 100644 index 0000000000..659c1ab48e --- /dev/null +++ b/.changeset/good-flowers-promise.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-backend': patch +--- + +Modified response when catalog entity isn't found to resolve issue where `/sync` endpoint was continuously called diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index b99579e0eb..4d5ba0ebf3 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -242,14 +242,14 @@ export async function createRouter( targetPluginId: 'catalog', }); - const entity = await entityLoader.load({ kind, namespace, name }, token); - - if (!entity?.metadata?.uid) { - throw new NotFoundError('Entity metadata UID missing'); - } - const responseHandler: DocsSynchronizerSyncOpts = createEventStream(res); + const entity = await entityLoader.load({ kind, namespace, name }, token); + if (!entity?.metadata?.uid) { + responseHandler.error(new NotFoundError('Entity metadata UID missing')); + return; + } + // By default, techdocs-backend will only try to build documentation for an entity if techdocs.builder is set to // 'local'. If set to 'external', it will assume that an external process (e.g. CI/CD pipeline // of the repository) is responsible for building and publishing documentation to the storage provider.