Hot to redirect in middleware when using createCallerFactory
Hello.
I do have this tiny middleware:
I am aware of redirect throws an error but it seems to be wrapped in a
result.error.cause
when thrown out so next can't realize that is redirect error and just ouputs Error: NEXT_REDIRECT to console.
isRedirectError(result.error) === false
while isRedirectError(result.error.cause) === true
Is there any known workaround for this to work?
Node 20 / npm 105 Replies
Also it seems to be related to https://discord.com/channels/867764511159091230/1096053768170258515/1096053768170258515
This appears to be tRPC working as designed
I don’t believe it’s possible to throw a redirect with NextJS APIs from within tRPC
You’d need to catch an error and handle it
(I can be wrong as I’m not a next user)
You’d need to catch an error and handle itI wish to, the thing is there is no way I can handle it because the error thrown is the handler itself
You’d throw a bespoke error and then handle that I believe, you can’t use next APIs in tRPC any more than you can use AngularJs in React
I imagine this as a flag / API to tell tRPC do not wrap that particular error in TrpcError that i am not aware of
Ahh I see your point here
A have also tried
to preted that is TRPC error but aparently it is not thrown but just logged.
Now the only solution seems to we wrapping the call in api that will allow to throw outside of caller factory (sounds like making a proxy object or so)
Since next 15 came out and it has it's own error handling function, the solution I had before (custom webpack plugin) had to be thrown away, so I had this question again
And now here is a solution: