mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
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:
+3
-1
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user