trpc error throwing and catching on the client

Hi I am throwing an error like this on the server:
throw new TRPCError({ code: 'CONFLICT', message: 'Email already exists!' });
throw new TRPCError({ code: 'CONFLICT', message: 'Email already exists!' });
And I'd like to catch it like this on the client:
if (error instanceof TRPCClientError) {

if (error.data.code === 'CONFLICT') {
form.setError('email', { message: 'Email is already taken' });
}
if (error instanceof TRPCClientError) {

if (error.data.code === 'CONFLICT') {
form.setError('email', { message: 'Email is already taken' });
}
However TRPCClientError doesnt assure me that data is there, how can I check it and still have full typesafety?
No description
1 Reply
stanisław
stanisławOP•14mo ago
error instanceof TRPCError however does what I want but the error thrown by useQuery is not instance of TRPCError 😄
Want results from more Discord servers?
Add your server