mellson
mellson
TtRPC
Created by Neon on 11/26/2022 in #❓-help
Throw custom TRPCError with specific cause
Ok, it was available in the error formatter when checking the error object. I only checked the shape and the output of the formatter. It seems you need to change the shape to include the cause. Is this intended behavior or some error on my end?
export const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
// I need to do this to get the cause passed to the client, is this intended?
...(error.cause && {
cause: error.cause.message,
}),
},
};
},
});
export const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
// I need to do this to get the cause passed to the client, is this intended?
...(error.cause && {
cause: error.cause.message,
}),
},
};
},
});
4 replies
TtRPC
Created by Neon on 11/26/2022 in #❓-help
Throw custom TRPCError with specific cause
I'm experiencing the same thing. If I throw an error on the server, something like this:
throw new TRPCError({
message: 'Hello from a bad request',
code: 'BAD_REQUEST',
cause: 'Custom cause', // get's converted to an Error by getCauseFromUnknown
});
throw new TRPCError({
message: 'Hello from a bad request',
code: 'BAD_REQUEST',
cause: 'Custom cause', // get's converted to an Error by getCauseFromUnknown
});
If I catch the error on the server, the cause is there. But in my errorFormatter, it is no longer present. Is the cause supposed to be present on the client side when using superjson?
4 replies
TtRPC
Created by mellson on 4/24/2023 in #❓-help
Full cache invalidation and timing problem
Thanks Alex! It was an error on my end. I put the onSuccess callback in the call to mutateAsync instead of putting it on the original useMutation 🤦 After moving it there, everything works as expected. I like your approach with putting noInvalidate on the meta; I'll do the same for us.
10 replies
TtRPC
Created by mellson on 4/24/2023 in #❓-help
Full cache invalidation and timing problem
Hey @alex / KATT sorry for the P.I.N.G 😅 But if you have a minute I'd love to understand this useMutation override a bit better
10 replies