notes.dt.in.th

Configuring tRPC error logging in T3 apps

Developers building apps on the using create-t3-app should be aware that tRPC error logging is disabled in production by default. This default can make it difficult to debug errors in production, as any errors thrown by tRPC will be swallowed (silently discarded) and not logged to the server console.

To enable tRPC error logging in production, edit the src/pages/api/trpc/[trpc].ts and set an onError handler:

  onError: ({ path, error }) => {
    if (env.NODE_ENV === "development") {
      console.error(`❌ tRPC failed on ${path}`);
    }
    console.error(error);
  }