Optimize Next.js memory and handle 404s

Configure startup and package-import optimizations, exclude generated Next.js files from TypeScript checks, and route fetch responses with status 404 to the not-found page.
This commit is contained in:
Ichsan Kurniawan
2026-11-18 18:20:27 +07:00
parent d4168b45f2
commit d10603acc8
4 changed files with 11 additions and 4 deletions
+3 -1
View File
@@ -1,4 +1,4 @@
import { redirect } from "next/navigation"
import { notFound, redirect } from "next/navigation"
import { ResponseData } from "@/types/types"
import { logger } from "./logger"
import { getCacheServerSession } from "./get-access-data"
@@ -24,6 +24,7 @@ export default async function fetchData(url: string = '/', cache: "default" | "f
console.log("FETCH ERROR DATA :", res.status, data)
if (res.status === 401 || res.status === 403) return redirect(`/auth?error=Session error or has expired !`)
if (res.status === 404) notFound()
// This will activate the closest `error.js` Error Boundary
throw new Error(`(${data.code || res.status}) ${data.message || res.statusText}`)
}
@@ -62,6 +63,7 @@ export async function fetchDataWithPost(url: string = '/', payload: any = {}, ca
console.log("FETCH ERROR DATA :", res.status, data)
if (res.status === 401 || res.status === 403) redirect(`/auth?error=Session error or has expired !`);
if (res.status === 404) notFound()
throw new Error(`(${data?.code || res.status} ${res.statusText}) ${data?.message}`);
}