Mugetsu
Mugetsu3y ago

Handling error globally

According to the docs on errors https://trpc.io/docs/v10/error-handling I should get such error object on client side when its thrown from procedure If I understand correctly. But Im having a problem with it as it doesnt seem to be typed as TRPCError on the client and dont contain few props from described in docs.
queryCache: new QueryCache({
onError: async (error: any) => {
console.log(error.id);
console.log(error.message);
console.log(error.code);
console.log(error.data);
console.log(error?.data?.httpStatus === 401);
if (
error?.data?.httpStatus === 401 ||
error.message === "UNAUTHORIZED"
) {
await signOut({ redirect: false });
}
},
}),
queryCache: new QueryCache({
onError: async (error: any) => {
console.log(error.id);
console.log(error.message);
console.log(error.code);
console.log(error.data);
console.log(error?.data?.httpStatus === 401);
if (
error?.data?.httpStatus === 401 ||
error.message === "UNAUTHORIZED"
) {
await signOut({ redirect: false });
}
},
}),
4 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Mugetsu
MugetsuOP3y ago
>All errors that occur in a procedure go through the onError method before being sent to the client I care about the part which lands on the client. Does it mean I cant get proper typings and all information regarding the error on the client? Or Am I doing something worng
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Mugetsu
MugetsuOP3y ago
Its not in my desire to define onerror for every query/mutation I make. I want a global error handler of 401 but I wonder why some info is missing from onError in QueryCache(global handler)