skagedal
Automatically decode custom errors on client
Hi! We're using tRPC v10.45.2 with React Query in a Next.js app. I'm looking for a nice way to pass custom error payloads to the browser. What I've done so far is have something like this:
Then, I create the TRPC context like this:
So far, all good! (Right? This is a good way to do this?)
But then, on the client side, I have to do something like this everywhere:
I guess that's not that bad, but it would be nice if I could just do something like:
So – is there a way to add some kind of middleware that decodes error payloads so your
onError
handlers for mutations and error
return value in queries could be simplified?2 replies
How can I get lint warnings for onSuccess/onError?
Maybe this isn't exactly a trpc question, but I'm thinking someone here would know. I would like to keep our project prepared for the transition to tRPC v.11 and the changes that come because of TanStack Query v.5.x. We have a lot of usage of onSuccess/onError in useQuery. So now I bumped tRPC to the latest 4.x (4.36.1) where they are marked as deprecated. I then realized that our lint setup does not warn for deprecations, so I added
eslint-plugin-deprecation
and enabled it per instructions. I then got a bunch of other deprecation warnings, so the plugin seems to be working, but nothing on these onSuccess / onError callbacks.
Is this supposed to be working this way, or is there another way I could make it work?2 replies