How to use the node-fetch.FetchError function in node-fetch

To help you get started, we’ve selected a few node-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Financial-Times / n-auto-logger / src / __tests__ / error-formatter.js View on Github external
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();
	});
});
github Financial-Times / n-auto-logger / src / __tests__ / failure-logger.js View on Github external
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]);
		});
github Financial-Times / n-auto-logger / src / __tests__ / error-formatter.js View on Github external
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();
	});
github decentralized-identity / sidetree / tests / bitcoin / BitcoinClient.spec.ts View on Github external
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'));
        }
      });