anton.johansson
anton.johansson
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
So I'd have to work with the data instead, which is most likely fine. 🙂
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Looks like the cause is undefined here
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Yeah I'll check!
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Yeah I get it, I just figured that you could allow "converting" a TRPCClientError into my own error before throwing it, but I'm not sure if it's worth the effort.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
I just like the idea of having the same error on the server and on the client, but it's more a personal thing.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
I had some thoughts first, but I think I can make it very similar with the TRPCClientError, I'm gonna mess around a bit with it. 🙂
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Yeah, but I'd love to be able to do something like this:
const myAction = trpc.myAction.useMutation();
const onClick = async () => {
try {
await myAction.mutateAsync();
} catch (error: unknown) {
if (error instanceof ApplicationError) {
// handle my own error type
} else {
// show some generic error
}
}
};
const myAction = trpc.myAction.useMutation();
const onClick = async () => {
try {
await myAction.mutateAsync();
} catch (error: unknown) {
if (error instanceof ApplicationError) {
// handle my own error type
} else {
// show some generic error
}
}
};
But I think this won't work, I'll have to work with the TRPCClientError.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
I'll see if I can easily work with TRPCClientError instead.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Well, I mostly want this because I feel it's clearer to handle my own error than a library-specific error. 🙂 But it probably does not matter much. Anyway, I tried messing around with transformer, but it looks like the entire framework is tightly coupled with the TRPCClientError type. The TRPCLink type "forces" TRPCClientError.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
@Nick Lucas Any ideas? Digging deep into the tRPC code at the moment, and it looks like the error must be of type TRPCClientError<MyRouter>. Otherwise, I could probably write my own httpBatchLink with custom error logic, but it looks like I can't.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
It feels like it should be relatively easy to hook in where the error object is being created, and convert it back to my own error type.
26 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Hmm, I'm still struggling a little bit with this. Is there no way to convert it back to my own custom error on the client side, in a "generic" way?
26 replies
TtRPC
Created by anton.johansson on 4/20/2023 in #❓-help
Next.js + tRPC, multitenancy, access Next.js Router when setting tRPC headers
I'm guessing I could skip @trpc/next and just go for @trpc/react-query directly.
3 replies
TtRPC
Created by anton.johansson on 4/3/2023 in #❓-help
Custom error management
Allright, I'll look into it, thanks Nick!
26 replies