export const handleApiError = async (response: Response) => {
  try {
    const json = await response.json();
    console.log({ json });
    const text = json.error ?? "unexpected error happpened";
    return new Error(text[0].toUpperCase() + text.slice(1));
  } catch (err) {
    try {
      console.log(err);
      const text = await response.text();
      if (text.length > 0) {
        return new Error(text[0].toUpperCase() + text.slice(1));
      }
    } catch (err) {
      console.log(err);
    }
  }

  return new Error("Unexpected error happened");
};
