fix: catalog:fetch to throw error for null entity
fixes #16447 Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
throw error from catalog:fetch scaffolder action when entity is null and optional is false
|
||||
@@ -90,7 +90,7 @@ describe('catalog:fetch', () => {
|
||||
expect(mockContext.output).toHaveBeenCalledWith('entity', null);
|
||||
});
|
||||
|
||||
it('should throw error if entity not in catalog and optional is false', async () => {
|
||||
it('should throw error if entity fetch fails from catalog and optional is false', async () => {
|
||||
getEntityByRef.mockImplementationOnce(() => {
|
||||
throw new Error('Not found');
|
||||
});
|
||||
@@ -109,4 +109,22 @@ describe('catalog:fetch', () => {
|
||||
});
|
||||
expect(mockContext.output).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw error if entity not in catalog and optional is false', async () => {
|
||||
getEntityByRef.mockReturnValueOnce(null);
|
||||
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
entityRef: 'component:default/test',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow('Entity component:default/test not found');
|
||||
|
||||
expect(getEntityByRef).toHaveBeenCalledWith('component:default/test', {
|
||||
token: 'secret',
|
||||
});
|
||||
expect(mockContext.output).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,6 +93,11 @@ export function createFetchCatalogEntityAction(options: {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (!entity && !optional) {
|
||||
throw new Error(`Entity ${entityRef} not found`);
|
||||
}
|
||||
|
||||
ctx.output('entity', entity ?? null);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user