How to use the node-fetch.Response 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 decentralized-identity / sidetree / tests / core / Observer.spec.ts View on Github external
function createReadableStreamResponse (content: object, status?: number): Response {
  // const stream = new Readable({ objectMode: true });
  const stream = new RepeatingReadable(content);
  stream.push(JSON.stringify(content));

  const response = new Response(stream, { status: status ? status : 200 });
  return response;
}
github Financial-Times / n-auto-logger / src / __tests__ / failure-logger.js View on Github external
it('fetch response error with status', async () => {
			const headers = new Headers();
			headers.append('content-type', 'text/plain; charset=utf-8');
			const errorResponse500 = new Response('500 Internal Server Error', {
				status: 500,
				headers,
			});
			await failureLogger()(errorResponse500);
			expect(logger.error.mock.calls).toHaveLength(1);
			assertErrorLog(logger.error.mock.calls[0][0]);

			const errorResponse404 = new Response('404 Not Found', {
				status: 404,
				headers,
			});
			await failureLogger()(errorResponse404);
			expect(logger.error.mock.calls).toHaveLength(1);
			expect(logger.warn.mock.calls).toHaveLength(1);
			assertErrorLog(logger.warn.mock.calls[0][0]);
		});
github frontity / frontity / packages / wp-source / src / libraries / handlers / __tests__ / mocks / helpers.ts View on Github external
export const mockResponse = (body, headers?): Response =>
  (new nodeFetch.Response(
    JSON.stringify(body),
    headers && {
      headers: new nodeFetch.Headers(headers)
    }
  ) as unknown) as Response;
github entropic-dev / entropic / services / common / boltzmann / response.js View on Github external
function error(err, status = 500, extraHeaders = {}) {
  const headers = new Headers({
    'content-type': 'application/json',
    ...extraHeaders
  });
  if (typeof err === 'string') {
    err = { message: err, code: 'ENOTSUPPLIED' };
  }

  if (isDev()) {
    err.trace = new Error().stack;
  }

  const r = new Response(JSON.stringify(err), { status, headers });
  return r;
}
github entropic-dev / entropic / services / common / boltzmann / response.js View on Github external
function empty(status = 204, headers = {}) {
  return new Response('', { status, headers });
}
github entropic-dev / entropic / services / common / boltzmann / response.js View on Github external
function bytes(stream, status = 200, extraHeaders = {}) {
  const headers = new Headers({
    'content-type': 'application/octet-stream',
    ...extraHeaders
  });
  const r = new Response(stream, { status, headers });
  return r;
}
github entropic-dev / entropic / services / common / boltzmann / response.js View on Github external
function text(body, status = 200, extraHeaders = {}) {
  const headers = new Headers({
    'content-type': 'text/plain',
    ...extraHeaders
  });
  const r = new Response(body, { status, headers });
  return r;
}
github entropic-dev / entropic / services / common / boltzmann / response.js View on Github external
function authneeded(message, status = 401, extraHeaders = {}) {
  const headers = new Headers({
    'www-authenticate': 'bearer',
    'content-type': 'application/json',
    ...extraHeaders
  });
  if (typeof message === 'string') {
    message = { message, code: 'authneeded' };
  }
  const r = new Response(JSON.stringify(message), { status, headers });
  return r;
}