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?0 Replies