kalempsterK
tRPC3y ago
2 replies
kalempster

Error types in catch block

Hey!

I have a mutation that I want to catch if the procedure throws an error, I'd like to get the code of the error ("UNAUTHORIZED", "FORBIDDEN" etc.) but TRCPClientError doesn't have full types (basically I can't access the code property). I saw a generic that you can pass to the error but I don't know what to pass as the generic to get the types.

try {
    await mutateAsync(id);
} catch (error) {
    if(error instanceof TRPCClientError<>){
        //Process the error here if unauthorized regenerate accessToken and retry
    }
}

Is there any way to do so?
Was this page helpful?