Merge pull request #27749 from backstage/vinzscam/catalog-client-query-endpoints-issue

catalog-client: fix queryEntities error handling
This commit is contained in:
Vincenzo Scamporlino
2024-11-21 12:16:34 +01:00
committed by GitHub
3 changed files with 20 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/catalog-client': patch
---
Fixed a bug in the `queryEntities` method where errors were not being handled properly.
@@ -525,6 +525,18 @@ describe('CatalogClient', () => {
'?cursor=prevcursor',
);
});
it('should handle errors', async () => {
const mockedEndpoint = jest
.fn()
.mockImplementation((_req, res, ctx) => res(ctx.status(401)));
server.use(rest.get(`${mockBaseUrl}/entities/by-query`, mockedEndpoint));
await expect(() => client.queryEntities()).rejects.toThrow(
/Request failed with 401 Unauthorized/,
);
});
});
describe('getEntityByRef', () => {
+3 -3
View File
@@ -237,9 +237,9 @@ export class CatalogClient implements CatalogApi {
}
}
return this.apiClient
.getEntitiesByQuery({ query: params }, options)
.then(r => r.json());
return this.requestRequired(
await this.apiClient.getEntitiesByQuery({ query: params }, options),
);
}
/**