T
tRPC

Zod Error Middleware

Zod Error Middleware

Zzomars11/15/2022
Hey lovely people. At Cal.com we make heavy use of zod for data validation. I was wondering if there's a way to create some kind of "error middleware" that can catch all Zod specific errors and serve the proper TRPC error back to the client. This would allow us to just use schema.parse instead of having to manually check schema.safeParse or having to use try/catch everywhere. Thanks for any input! šŸ™
UUUnknown User11/15/2022
2 Messages Not Public
Sign In & Join Server To View
Zzomars11/15/2022
Not quite what I'm asking. Yeah I basically want to allow zod to fail anywhere (right now it just throws a 500). Catch that error en a middleware and respond a proper 400 with a better error message.
UUUnknown User11/15/2022
Message Not Public
Sign In & Join Server To View
Zzomars11/15/2022
I don't think you can modify the error there
UUUnknown User11/16/2022
3 Messages Not Public
Sign In & Join Server To View
AKAlex / KATT šŸ±11/16/2022
Are you sure you want this? Do you ever use zod for stuff that isn't for validation? I feel like doing this might mask stuff that are actually internal errors Can you link me to a couple zod parsers within your codebase that you'd want to propagate as bad requests? Maybe there's another way of approaching But yes, this should be possible through the error formatter

Looking for more? Join the community!

T
tRPC

Zod Error Middleware

Join Server
Recommended Posts
clear cookie onErrorI'd like to clear a cookie (in nextjs) when a 403 error happens. I've been looking at the global errRequest context from getServerSidePropsThe docs of tRPC context https://trpc.io/docs/v10/context ``` export async function createContext(oAuth with passport.jsEvening all, Has anyone successfully setup trpc with passport.js for auth?Object keeps getting overwrittenI feel like i'm missing something fundamental here. when I add a new entry into object ``b`` it resAccessToken for API callsWhat would be the best approach to pass the AccessToken from NextAuth Session to the Http Client whiRequest or Response Specification Definition DocumentI am developing a backend service using trpc, but I need to dispatch trpc in another programming lanabortOnUnmount config errorI'm encountering an error when passing abortOnUnmount saying that it does not exist as a possible pazustand + trpc (basic data fetching)im trying to use zustand with trpc, but having trouble setting some data to global state. What am i TypeError Cannot destructure property 'abortOnUnmount' of 'useContext(...)' as it is null.Zero Clue what is error mean exactly....First time learning trpc really good tool. help with setting cookies on front end.Hello how do you use tRPC to make a cookie and send it to the front end. or is there any other methoHow do we add settings in each query like before?Since the new update, bee super confused. I used to do this, and can't recreate it now. ``` const Handling error globallyAccording to the docs on errors https://trpc.io/docs/v10/error-handling I should get such error objecant access trpc endpoints via the browseri'm converting some express endpoints to trpc, and I cant figure out how to access my endpoints via tRPC without SSRWhen using tRPC with ssr it uses `getInitialProps`, which has kinda of a cool effect in terms how a trpc + expo react native issueDoes anyone know how to solve this? Im not familiar with webpack at all. Iā€™m a junior frontend.Can you chain middlewares in v10?Would I be able to make a rate limit and isAuthed middleware, then put queries behind both middlewarLoad data client-side via react-query while using tRPC with SSRIs there any way to load data client-side when using tRPC? I want my page to be rendered and load daServing clients in another repository?Would it be possible for tRPC to act as a server for clients in another repository and if so how wouWhen not to use tRPC?Is there any scenario when building a mobile and/or a web app with backend that you would not recommBi directional infinite query example with prismaI'm working on a project that is using this pattern, but my `hasPreviousPages` gets blown away when