MugetsuM
tRPC3y ago
2 replies
Mugetsu

Enigmatic INTERNAL SERVER ERROR

Im having a problem finding out about what is causing the INTERNAL SERVER ERROR from tRPC in my production.
This is the error 👀
{
    "level": "error",
    "message": {
        "cause": {},
        "code": "INTERNAL_SERVER_ERROR",
        "name": "TRPCError"
    },
    "timestamp": "2023-03-23T12:14:12.710Z",
    "traceId": "...."
}


Are there any recommendation on how to handle onError handler for production ??
This is my current approach which seems to swallow some information. Can't really tell where it originates and how to possibly overcome it

    trpcExpress.createExpressMiddleware({
      router: appRouter,
      createContext: createTRPCContext,
      onError: ({ path: errorPath, error, ctx }) => {
        const message = isDevelopment
          ? `❌❌❌ tRPC failed on ${errorPath ?? '<no-path>'}: ${
              error.message
            }`
          : error

        if (error.code === 'INTERNAL_SERVER_ERROR')
          ctx.req.logger.error(message)
        else ctx.req.logger.warn(message)
      },
    })
Was this page helpful?