Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('format network error correctly', async () => {
const e = new nodeFetch.FetchError(
'request to https://mock.com/ failed, reason: unable to verify the first certificate',
);
e.code = 'UNABLE_TO_VERIFY_LEAF_SIGNATURE';
const formatted = await formatFetchNetworkError(e);
expect(formatted.category).toBe(CATEGORIES.FETCH_NETWORK_ERROR);
expect(formatted).toMatchSnapshot();
});
});
it('fetch network error', async () => {
const e = new FetchError(
'request to https://unknown/ failed, reason: some reason',
);
e.code = 'ENOTFOUND';
await failureLogger()(e);
expect(logger.error.mock.calls).toHaveLength(1);
assertErrorLog(logger.error.mock.calls[0][0]);
});
it('format network error correctly', async () => {
const e = new nodeFetch.FetchError(
'request to https://mock.com/ failed, reason: unable to verify the first certificate',
);
e.code = 'UNABLE_TO_VERIFY_LEAF_SIGNATURE';
const formatted = await formatFetchError(e);
expect(formatted.category).toBe(CATEGORIES.FETCH_NETWORK_ERROR);
expect(formatted).toMatchSnapshot();
});
fetchSpy.and.callFake((_: any, params: any) => {
expect(params.headers.id).toEqual(requestId, 'Fetch was not called with request parameters');
if (timeout) {
expect(params.timeout).toBeGreaterThan(timeout, 'Fetch was not called with an extended timeout');
return Promise.resolve();
} else {
timeout = params.timeout;
return Promise.reject(new nodeFetchPackage.FetchError('test', 'request-timeout'));
}
});