t3-oss / create-t3-app

The best way to start a full-stack, typesafe Next.js app
https://create.t3.gg
MIT License
25.08k stars 1.15k forks source link

bug: Manually thrown TRPC errors do not behave as expected on the client #1966

Closed lingsuann02 closed 1 month ago

lingsuann02 commented 1 month ago

Provide environment information

System: OS: Linux 6.1 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (2) x64 AMD EPYC Memory: 2.17 GB / 4.01 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 20.12.1 - /home/codespace/nvm/current/bin/node Yarn: 1.22.19 - /usr/bin/yarn npm: 10.5.0 - /home/codespace/nvm/current/bin/npm pnpm: 8.15.6 - /home/codespace/nvm/current/bin/pnpm


"ct3aMetadata": { "initVersion": "7.36.2" },

Describe the bug

Hi!

I've just started playing around with TRPC so this could be a result of my lack of understanding of how things work, but I've tried to check the documentation and troubleshoot this issue without any luck. So here goes:

Errors thrown in the server does not seem to resolve in a failed request in the browser or trigger the expected onError callback in react-query.

Given this example query:

  const { data: helloData, error: helloError } = api.post.hello.useQuery({
    text: "from tRPC",
  });

and this procedure

  hello: publicProcedure
    .input(z.object({ text: z.string() }))
    .query(({ input }) => {
      throw new TRPCError({
        code: "INTERNAL_SERVER_ERROR",
      });
    }),

Expected result: A response with the correct error code. Actual result: The response is appears to be pending infinitely in the browser and a 200 in the logs.

Screenshot 2024-08-13 at 02 57 51 Screenshot 2024-08-13 at 03 05 24

I'd really like to use this setup for a project of mine. I must be doing something wrong - please help! :)

Reproduction repo

Link

To reproduce

  1. Run npm create t3-app@latest
  2. Choose Typescript, Tailwind CSS, tRPC, No authentication, Prisma, Nextjs App Router
  3. Throw a TRPC error in any query.

Sandbox has been created and linked.

Additional information

The query also seems to be retried infinitely when null is returned on the server. Other people in this thread have also been experiencing this: https://github.com/trpc/trpc/discussions/5919?sort=new Not sure if it's related to the bug with errors though?

lingsuann02 commented 1 month ago

Sounds awfully familiar to https://github.com/t3-oss/create-t3-app/issues/1965 I'm not sure if it is a duplicate though? If so, feel free to close this!

lingsuann02 commented 1 month ago

Closing because I realised that error object does seem to resolve after the request has been retried three times. This does result in some latency, but I think that this is something I can configure.