aryzing
aryzing9mo ago

How to make typed error responses in the context of a specific query?

Each query has a typed (success) response, although it seems all queries have a shared type for the error response. Is there a way of having per-query typed error responses? Is there a better alternative to having an error within a successful response, as below?
const appRouter = router({
foo: publicProcedure.query(() => {
const [error, data] = doSomething();

if (error) return {
isSuccess: false,
error,
};

return {
isSuccess: true,
data
};
})
});
const appRouter = router({
foo: publicProcedure.query(() => {
const [error, data] = doSomething();

if (error) return {
isSuccess: false,
error,
};

return {
isSuccess: true,
data
};
})
});
0 Replies
No replies yetBe the first to reply to this messageJoin