I am wondering if it is possible to properly type my "cause.code"? I am hoping to create custom error codes so my frontend can decide which type of UI to display to the user. But, ideally this would be in a typesafe way so im not guessing what the error codes are. Is there a way i can tell trpc this, without having to use as CustomErrorCodesas CustomErrorCodes in every instance I want to use it in?
client:
const { error: invalidCaptcha } = await tryCatch( api.verification.isCaptchaValid({ guildId, uuid }), ); console.log(invalidCaptcha?.cause?.code); // Property code does not exist on type {}.
const { error: invalidCaptcha } = await tryCatch( api.verification.isCaptchaValid({ guildId, uuid }), ); console.log(invalidCaptcha?.cause?.code); // Property code does not exist on type {}.
server:
if (!verificationCache) { throw new TRPCError({ code: "BAD_REQUEST", message: "This captcha has expired.", cause: { code: "CAPTCHA_EXPIRED", }, }); }
if (!verificationCache) { throw new TRPCError({ code: "BAD_REQUEST", message: "This captcha has expired.", cause: { code: "CAPTCHA_EXPIRED", }, }); }
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
t
tRPC
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.