-
Hello, What would be the easiest way to setup a global error handler on the client? (React + tanstack query) Going through the doc: https://orpc.unnoq.com/docs/tanstack-query/basic#error-handling To have it globally for mutations, I can do: export const queryClient = new QueryClient({
defaultOptions: {
mutations: {
onError: error => {
console.log("Got error", error);
}
}
}
}); But for queries, there is no Any other idea? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I think TanStack has a way to listen for query errors, though I'm not sure since I haven't used it in a while. But in oRPC, you can handle that using the |
Beta Was this translation helpful? Give feedback.
-
For those finding this thread through search, the following works well: const link = new RPCLink({
url: "...",
interceptors: [
options => {
return options.next().catch(error => {
if (error instanceof ORPCError) {
notifications.show({
title: "Error",
message: error.message,
color: "red"
});
}
throw error;
});
}
]
}); |
Beta Was this translation helpful? Give feedback.
I think TanStack has a way to listen for query errors, though I'm not sure since I haven't used it in a while. But in oRPC, you can handle that using the
interceptors
option inRPCLink