Skip to content

Commit 18004b0

Browse files
committed
cleanup toasts
1 parent 5e98272 commit 18004b0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

apps/dashboard/app/providers.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,44 @@ const defaultQueryClientOptions = {
3535
},
3636
};
3737

38+
function isAuthError(error: unknown): boolean {
39+
if (!error || typeof error !== "object") {
40+
return false;
41+
}
42+
43+
const rpcError = error as {
44+
data?: { code?: string; message?: string };
45+
code?: string;
46+
message?: string;
47+
};
48+
49+
const errorCode = rpcError.data?.code ?? rpcError.code;
50+
if (errorCode === "UNAUTHORIZED" || errorCode === "AUTH_REQUIRED") {
51+
return true;
52+
}
53+
54+
const errorMessage = (
55+
rpcError.data?.message ??
56+
rpcError.message ??
57+
String(error)
58+
).toLowerCase();
59+
60+
return (
61+
errorMessage.includes("authentication") ||
62+
errorMessage.includes("unauthorized") ||
63+
errorMessage.includes("unauthenticated") ||
64+
errorMessage.includes("401")
65+
);
66+
}
67+
3868
const queryClient = new QueryClient({
3969
defaultOptions: defaultQueryClientOptions.defaultOptions,
4070
queryCache: new QueryCache({
4171
onError: (error) => {
72+
if (isAuthError(error)) {
73+
return;
74+
}
75+
4276
const message = error instanceof Error ? error.message : "Unknown error";
4377
toast.error(message);
4478
trackError(message, {
@@ -50,6 +84,10 @@ const queryClient = new QueryClient({
5084
}),
5185
mutationCache: new MutationCache({
5286
onError: (error) => {
87+
if (isAuthError(error)) {
88+
return;
89+
}
90+
5391
const message = error instanceof Error ? error.message : "Unknown error";
5492
toast.error(message);
5593
trackError(message, {

0 commit comments

Comments
 (0)