mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 17:00:54 +01:00
24 lines
602 B
TypeScript
24 lines
602 B
TypeScript
|
|
import "server-only";
|
||
|
|
|
||
|
|
import { notFound, redirect } from "next/navigation";
|
||
|
|
import { TRPCError } from "@trpc/server";
|
||
|
|
|
||
|
|
import { logger } from "@homarr/log";
|
||
|
|
|
||
|
|
export const catchTrpcNotFound = (err: unknown) => {
|
||
|
|
if (err instanceof TRPCError && err.code === "NOT_FOUND") {
|
||
|
|
notFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
throw err;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const catchTrpcUnauthorized = (err: unknown) => {
|
||
|
|
if (err instanceof TRPCError && err.code === "UNAUTHORIZED") {
|
||
|
|
logger.info("Somebody tried to access a protected route without being authenticated, redirecting to login page");
|
||
|
|
redirect("/auth/login");
|
||
|
|
}
|
||
|
|
|
||
|
|
throw err;
|
||
|
|
};
|