don't surface non-FetchErrors
It makes sense to gracefully show an error that was actually related to fetching data from Kubernetes, but if the error is happening for some other exotic reason, the default error handling logic in Backstage should take over and log/manage it appropriately. Signed-off-by: Jamie Klassen <jklassen@vmware.com>
This commit is contained in:
@@ -757,6 +757,27 @@ describe('getKubernetesObjectsByEntity', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
it('fails when fetcher rejects with a non-FetchError', async () => {
|
||||
const nonFetchError = new Error('not a fetch error');
|
||||
getClustersByEntity.mockResolvedValue({
|
||||
clusters: [
|
||||
{
|
||||
name: 'test-cluster',
|
||||
authProvider: 'serviceAccount',
|
||||
skipMetricsLookup: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
fetchObjectsForService.mockRejectedValue(nonFetchError);
|
||||
|
||||
const sut = getKubernetesFanOutHandler([]);
|
||||
|
||||
const result = sut.getKubernetesObjectsByEntity({
|
||||
entity,
|
||||
auth: {},
|
||||
});
|
||||
await expect(result).rejects.toThrow(nonFetchError);
|
||||
});
|
||||
describe('with a real fetcher', () => {
|
||||
const worker = setupServer();
|
||||
setupRequestMockHandlers(worker);
|
||||
|
||||
@@ -274,15 +274,20 @@ export class KubernetesFanOutHandler {
|
||||
namespace,
|
||||
})
|
||||
.then(result => this.getMetricsForPods(clusterDetailsItem, result))
|
||||
.catch((e): responseWithMetrics => {
|
||||
return [
|
||||
{
|
||||
errors: [{ errorType: 'FETCH_ERROR', message: e.message }],
|
||||
responses: [],
|
||||
},
|
||||
[],
|
||||
];
|
||||
})
|
||||
.catch(
|
||||
(e): Promise<responseWithMetrics> =>
|
||||
e.name === 'FetchError'
|
||||
? Promise.resolve([
|
||||
{
|
||||
errors: [
|
||||
{ errorType: 'FETCH_ERROR', message: e.message },
|
||||
],
|
||||
responses: [],
|
||||
},
|
||||
[],
|
||||
])
|
||||
: Promise.reject(e),
|
||||
)
|
||||
.then(r => this.toClusterObjects(clusterDetailsItem, r));
|
||||
}),
|
||||
).then(this.toObjectsByEntityResponse);
|
||||
|
||||
Reference in New Issue
Block a user