import fetch, { Response } from 'node-fetch'; import { HttpRequest } from '../types/request'; import { responseError } from '../helpers/response-error'; /** * A function that makes a HTTP request with the HEAD method * @param url URL for the request * @param key secret key for the request * @param additionalHeaders any headers that are additional to contentType and x-api-key * @returns it returns a HTTP promise response */ export async function head({ url, key, additionalHeaders = {} }: HttpRequest, fetch: Function): Promise { const options = { method: 'HEAD', headers: { 'X-api-key': key, ...additionalHeaders } }; const response: Response = await fetch(url, options); if (!response.ok) { const request = { url, method: options.method }; throw await responseError(response, request); } return response; }