Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
14 replies
rustclan

TRPC max retries on endpoint

export const authRouter = router({
  getSession: publicProcedure.query(({ ctx }) => {
    // if (!ctx.session || !ctx.session.user?.accessToken) {
    if (true) {
      throw new TRPCError({
        code: "UNAUTHORIZED",
        message: "Not logged in",
        cause: "No session",
      });
    }
    return ctx.session;
  }),

  const session = trpc.auth.getSession.useQuery(undefined, {
    onError: (err) => {
      console.log(1)
      return signIn();
    },
  });

Hi,

for some reason, when the api endpoint errors it reruns the request 3 times, and then on the last time if it errors again it will then emit the onError event. Is there a setting which I am unaware of which trys to rerun the requests x amount of times?

This results in the page loading for a number of seconds before the user is forced to login with the nextauth signIn function.

Checking the console, the error is thrown every time. (In the picture, this is the result of one unauthorized page load)

I've had a look at the docs here: https://trpc.io/docs/v9/error-handling
and didn't see anything about a auto retry or max retries function/property?
unknown.png
Was this page helpful?