infodusha
infodusha
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
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:
const caller = createCallerFactory(apiRouter);
const createContext = cache(async () => {
...
});
export const directApi = caller(createContext, {
onError(ctx) {
if (isNotFoundError(ctx.error.cause) || isRedirectError(ctx.error.cause)) {
throw ctx.error.cause;
}
},
});
const caller = createCallerFactory(apiRouter);
const createContext = cache(async () => {
...
});
export const directApi = caller(createContext, {
onError(ctx) {
if (isNotFoundError(ctx.error.cause) || isRedirectError(ctx.error.cause)) {
throw ctx.error.cause;
}
},
});
13 replies
TtRPC
Created by ViliamKopecky on 11/9/2023 in #❓-help
Next.js tRPC router separated to edge-runtime and node-runtime
Can't split link help in your case?
4 replies
TtRPC
Created by mithrandir on 6/2/2024 in #❓-help
is there a way to fetch real time data in server side instead of client side(invalidate)?
You mean createCaller method?
3 replies
TtRPC
Created by warflash on 6/1/2024 in #❓-help
How to prevent leaking error messages to client?
you can write a middleware that with catch your errors and rethrow them with less info
4 replies
TtRPC
Created by LunaCrafts on 5/28/2024 in #❓-help
Using tRPC (createCallerFactory) with react-query.
Ahh I see now. So you kinda want to use trpc as a data layer but on the client... And you still want to use react-query integration because under the hood this "data layer" still make requests, am I right?
8 replies
TtRPC
Created by LunaCrafts on 5/28/2024 in #❓-help
Using tRPC (createCallerFactory) with react-query.
Hello. What do you expect from this approach? The error comes from a thing, createCallerFactory is a server method, not a client method. It totally makes no sese to provide server code in the client provider.
8 replies
TtRPC
Created by Jacob on 5/27/2024 in #❓-help
Losing type-safety with merged routers
That probably could also be a result of circular imports? Check if users.ts imports something from router.ts.
5 replies
TtRPC
Created by Jonathan on 5/16/2024 in #❓-help
TRPC completely broke
So it says you have not added 'use client' directive to the FormContext file
5 replies
TtRPC
Created by Mugetsu on 2/14/2024 in #❓-help
onError callback type
Probably you can type it like:
{
onError: (err: TRPCClientErrorLike<unknown>) => void
}
{
onError: (err: TRPCClientErrorLike<unknown>) => void
}
6 replies
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
A have also tried
const redirectError = getRedirectError('/logout', RedirectType.push, RedirectStatusCode.TemporaryRedirect);
const trpcError = new TRPCError({
message: redirectError.message,
code: 'UNAUTHORIZED',
cause: redirectError.cause,
});
const magicError = Object.assign(redirectError, trpcError);
throw magicError;
const redirectError = getRedirectError('/logout', RedirectType.push, RedirectStatusCode.TemporaryRedirect);
const trpcError = new TRPCError({
message: redirectError.message,
code: 'UNAUTHORIZED',
cause: redirectError.cause,
});
const magicError = Object.assign(redirectError, trpcError);
throw magicError;
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)
13 replies
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
Ahh I see your point here
13 replies
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
I imagine this as a flag / API to tell tRPC do not wrap that particular error in TrpcError that i am not aware of
13 replies
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
You’d need to catch an error and handle it
I wish to, the thing is there is no way I can handle it because the error thrown is the handler itself
13 replies
TtRPC
Created by infodusha on 2/9/2024 in #❓-help
Hot to redirect in middleware when using createCallerFactory
13 replies