Next.js Discord

Discord Forum

Visible errors in console

Unanswered
Shu posted this in #help-forum
Open in Discord
ShuOP
It is normal that console errors are visible in production? Should I care about that and is that fault of my code?

I use SWR for client side fetching, on their website they provided and example in which they throw an error.

Below is my code.

export const fetcher = async <T>({ fetchUrl, fetchOptions }: FetcherInput) => {
  const res = await fetch(fetchUrl, fetchOptions);

  if (!res.ok) {
    const error = new SwrError();
    const msg = await res.json();

    error.message = msg.message ?? "Something went wrong";
    error.status = res.status;
    throw error;
  }
  try {
    return (await res.json()) as T;
  } catch {
    return {} as T;
  }
};


export const useMe = (options?: SWRConfiguration) => {
  const fetchUrl = `${process.env.SERVER_URL}/me`;

  const fetchOptions: RequestInit = {
    credentials: "include",
  };

  const { data, error, isLoading } = useSWR<Me, SwrError>(
    { fetchUrl, fetchOptions },
    fetcher,
    options
  );

  return {
    data,
    isError: error,
    isLoading,
  };
};

2 Replies