/ src / utils / tFetch.ts
tFetch.ts
 1  export const tFetch = <T>(url: string, opts?: RequestInit): Promise<T> => {
 2    return fetch(url, opts).then((response) => {
 3      if (!response.ok) {
 4        throw new Error(response.statusText);
 5      }
 6      // HEAD Method doesn't return anything in the body, so response.json() fails, since it's only a method to check
 7      // if the resource is available it's okay to return never
 8      if (opts?.method === 'HEAD') return Promise.resolve() as Promise<never>;
 9      return response.json() as Promise<T>;
10    });
11  };