All files / client http.js

90% Statements 9/10
66.66% Branches 4/6
100% Functions 2/2
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 235x 4x 4x 2x   2x 2x             1x               1x  
const createHttpHandlerWithMethod = (method) => async (url, options) => {
  const response = await fetch(url, { ...options, method });
  if (!response.ok) {
    throw new Error(`${response.status} ${response.statusText}`);
  }
  Eif (response.status === 200) {
    return response.headers.get('Content-Type') === 'application/json'
      ? response.json()
      : response.text();
  }
  return undefined;
};
 
const http = {
  get: createHttpHandlerWithMethod('GET'),
  post: createHttpHandlerWithMethod('POST'),
  put: createHttpHandlerWithMethod('PUT'),
  patch: createHttpHandlerWithMethod('PATCH'),
  delete: createHttpHandlerWithMethod('DELETE'),
};
 
export default http;