tRPCttRPC
Powered by
aryzingA
tRPC•3y ago•
1 reply
aryzing

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
    };
  })
});
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to use querykeys from react-query
DR33MDDR33M / ❓-help
3y ago
How to get the type of context after middleware context extension?
cha0sg0dCcha0sg0d / ❓-help
3y ago
How to infer types of a query
HussamHHussam / ❓-help
3y ago
Unsafe assignment of an error typed value
brunubBbrunub / ❓-help
16mo ago