diff --git a/apps/infoalloggi/src/pages/api/trpc/[trpc].ts b/apps/infoalloggi/src/pages/api/trpc/[trpc].ts index 4522c56..8df2499 100644 --- a/apps/infoalloggi/src/pages/api/trpc/[trpc].ts +++ b/apps/infoalloggi/src/pages/api/trpc/[trpc].ts @@ -9,7 +9,10 @@ export default createNextApiHandler({ createContext: createTRPCContext, onError: ({ path, error }) => { - if (error.message.startsWith("SESSION_EXPIRED")) { + if ( + error.message.startsWith("SESSION_EXPIRED") || + error.code === "UNAUTHORIZED" + ) { return; } if (env.NODE_ENV === "development") { diff --git a/apps/infoalloggi/src/utils/api.ts b/apps/infoalloggi/src/utils/api.ts index 7684425..437b6fc 100644 --- a/apps/infoalloggi/src/utils/api.ts +++ b/apps/infoalloggi/src/utils/api.ts @@ -44,6 +44,7 @@ const errorLink: TRPCLink = () => { err, ); window.location.reload(); + return; } observer.error(err); }, @@ -60,12 +61,27 @@ export const api = createTRPCNext({ links: [ errorLink, loggerLink({ - enabled: (opts) => - (process.env.NODE_ENV === "development" && - typeof window !== "undefined") || - (opts.direction === "down" && - opts.result instanceof Error && - !opts.result.message.startsWith("SESSION_EXPIRED")), + enabled: (opts) => { + const isDev = process.env.NODE_ENV === "development"; + + if (opts.direction === "down" && opts.result instanceof Error) { + const isIgnoredError = + opts.result.message.startsWith("SESSION_EXPIRED") || + opts.result.data?.code === "UNAUTHORIZED"; + if (!isIgnoredError) { + return true; + } + if (isDev) { + console.warn("Following error is ignored in production:"); + return true; + } + return false; + } + if (isDev) { + return true; + } + return false; + }, }), splitLink({