<commit_before>export const addJsonHeaders = fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    headers.set('Accept', 'application/json');
    headers.set('Content-Type', 'application/json');
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const addAuthToken = (getToken, keyword = 'Token') => fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    const token = getToken();
    if (token) {
      headers.set('Authorization', `${keyword} ${getToken()}`);
    }
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const addCsrfToken = getToken => fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    headers.set('X-CSRFToken', getToken());
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const logRequest = fetchFunc => {
  const next = (url, init = {}) => {
    console.log('Making request:', url, init);
    return fetchFunc(url, init);
  };
  return next;
};

export const thenCombineResponse = fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(
      response =>
        response.ok ? { response } : { error: { fetchResponse: response } },
      typeError => ({ error: { typeError } })
    );
  };
  return next;
};

export const thenJson = fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(({ response, error }) => {
      if (response) {
        try {
          return response.json().then(
            json => ({ response: json }),
            () => {
              throw new Error({ message: 'No JSON in response', response });
            }
          );
        } catch (error) {
          throw new Error({ message: 'No JSON in response', response });
        }
      }
      if (error && error.fetchResponse) {
        return error.fetchResponse
          .json()
          .then(json => ({ error: { ...error, json } }), () => ({ error }));
      } else {
        return { response, error };
      }
    });
  };
  return next;
};

export const thenFormatResponse = formatter => fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(response => formatter(response));
  };
  return next;
};

export const thenLogResponse = fetchFunc => {
  const next = (url, init = {}) => {
    return fetchFunc(url, init).then(response => {
      console.log('Response:', response);
      return response;
    });
  };
  return next;<commit_msg>Remove throw error if no json<commit_after>export const addJsonHeaders = fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    headers.set('Accept', 'application/json');
    headers.set('Content-Type', 'application/json');
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const addAuthToken = (getToken, keyword = 'Token') => fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    const token = getToken();
    if (token) {
      headers.set('Authorization', `${keyword} ${getToken()}`);
    }
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const addCsrfToken = getToken => fetchFunc => {
  const next = (url, init = {}) => {
    const headers = init.headers || new Headers();
    headers.set('X-CSRFToken', getToken());
    return fetchFunc(url, { ...init, headers });
  };
  return next;
};

export const logRequest = fetchFunc => {
  const next = (url, init = {}) => {
    console.log('Making request:', url, init);
    return fetchFunc(url, init);
  };
  return next;
};

export const thenCombineResponse = fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(
      response =>
        response.ok ? { response } : { error: { fetchResponse: response } },
      typeError => ({ error: { typeError } })
    );
  };
  return next;
};

export const thenJson = fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(({ response, error }) => {
      if (response) {
        return response
          .json()
          .then(json => ({ response: json }), () => ({ response }));
      }
      if (error && error.fetchResponse) {
        return error.fetchResponse
          .json()
          .then(json => ({ error: { ...error, json } }), () => ({ error }));
      } else {
        return { response, error };
      }
    });
  };
  return next;
};

export const thenFormatResponse = formatter => fetchFunc => {
  const next = (url, init) => {
    return fetchFunc(url, init).then(response => formatter(response));
  };
  return next;
};

export const thenLogResponse = fetchFunc => {
  const next = (url, init = {}) => {
    return fetchFunc(url, init).then(response => {
      console.log('Response:', response);
      return response;
    });
  };
  return next;
{'fraction_non_alphanumeric': 0.17419225366245233, 'fraction_numerical': 0.0, 'mean_word_length': 2.637956204379562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7546609', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1489, 'n_words': 393}