remove console logging in prod
This commit is contained in:
@@ -12,11 +12,40 @@ const getBaseUrl = () => {
|
|||||||
return `http://localhost:${process.env.PORT ?? 3000}`;
|
return `http://localhost:${process.env.PORT ?? 3000}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Custom fetch that suppresses 401 console errors
|
||||||
|
const customFetch: typeof fetch = async (input, init?) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(input, init);
|
||||||
|
// Suppress logging for 401 errors by cloning and not throwing
|
||||||
|
if (response.status === 401) {
|
||||||
|
// Return the response without logging to console
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
// Only re-throw non-401 errors
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const api = createTRPCProxyClient<AppRouter>({
|
export const api = createTRPCProxyClient<AppRouter>({
|
||||||
links: [
|
links: [
|
||||||
// will print out helpful logs when using client
|
// will print out helpful logs when using client (suppress 401 errors)
|
||||||
loggerLink(),
|
loggerLink({
|
||||||
|
enabled: (opts) => {
|
||||||
|
// Only log in development, and suppress 401 errors
|
||||||
|
const isDev = process.env.NODE_ENV === "development";
|
||||||
|
const is401 =
|
||||||
|
opts.direction === "down" &&
|
||||||
|
opts.result instanceof Error &&
|
||||||
|
opts.result.message?.includes("UNAUTHORIZED");
|
||||||
|
return isDev && !is401;
|
||||||
|
}
|
||||||
|
}),
|
||||||
// identifies what url will handle trpc requests
|
// identifies what url will handle trpc requests
|
||||||
httpBatchLink({ url: `${getBaseUrl()}/api/trpc` })
|
httpBatchLink({
|
||||||
|
url: `${getBaseUrl()}/api/trpc`,
|
||||||
|
fetch: customFetch
|
||||||
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user