This is a better fix. Docs for Azure/fetch-event-source mention you should re-throw the error in the onerror function to stop operation

Signed-off-by: Alex Lorenzi <alorenzi@spotify.com>
This commit is contained in:
Alex Lorenzi
2025-02-12 18:22:44 -05:00
parent 060453e701
commit 840a2687fe
3 changed files with 7 additions and 24 deletions
@@ -164,14 +164,7 @@ describe('createRouter', () => {
.set('accept', 'text/event-stream')
.send();
expect(response.status).toBe(200);
expect(response.get('content-type')).toBe('text/event-stream');
expect(response.text).toEqual(
`event: error
data: "Entity not found"
`,
);
expect(response.status).toBe(404);
});
it('should return not found if entity has no uid', async () => {
@@ -186,14 +179,7 @@ data: "Entity not found"
.set('accept', 'text/event-stream')
.send();
expect(response.status).toBe(200);
expect(response.get('content-type')).toBe('text/event-stream');
expect(response.text).toEqual(
`event: error
data: "Entity metadata UID missing"
`,
);
expect(response.status).toBe(404);
});
it('should not check for an update when shouldBuild returns false', async () => {
@@ -242,18 +242,14 @@ export async function createRouter(
targetPluginId: 'catalog',
});
const responseHandler: DocsSynchronizerSyncOpts = createEventStream(res);
const entity = await entityLoader.load({ kind, namespace, name }, token);
if (!entity?.metadata?.uid) {
responseHandler.error(
new NotFoundError(
entity ? 'Entity metadata UID missing' : 'Entity not found',
),
);
return;
throw new NotFoundError('Entity metadata UID missing');
}
const responseHandler: DocsSynchronizerSyncOpts = createEventStream(res);
// 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.
+1
View File
@@ -236,6 +236,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
onerror(err) {
ctrl.abort();
reject(err);
throw err; // rethrow to stop the operation
},
});
});