T
tRPC

❓-help

Middleware that returns data instead of throwing error

Vvaltyr1/2/2024
Is there any way for a middleware to return typed data instead of throwing an error? I can only see examples of the latter. I'm thinking about something like this:
procedure.use((opts) => {
if(/*...*/) return {type: 'error'} as const;
return opts.next(opts);
})
procedure.use((opts) => {
if(/*...*/) return {type: 'error'} as const;
return opts.next(opts);
})
It would then augment the output type of the procedure with the output type of the middleware.

Looking for more? Join the community!