import type { FC } from "react"; import grabDirNames from "../../../utils/grab-dir-names"; import type { BunextPageModule, BunxRouteParams, GrabPageComponentRes, } from "../../../types"; type Params = { error?: any; routeParams?: BunxRouteParams; is404?: boolean; }; export default async function grabPageErrorComponent({ error, routeParams, is404, }: Params): Promise { const router = global.ROUTER; const { BUNX_ROOT_500_PRESET_COMPONENT, BUNX_ROOT_404_PRESET_COMPONENT } = grabDirNames(); const errorRoute = is404 ? "/404" : "/500"; const presetComponent = is404 ? BUNX_ROOT_404_PRESET_COMPONENT : BUNX_ROOT_500_PRESET_COMPONENT; try { const match = router.match(errorRoute); const filePath = match?.filePath || presetComponent; const bundledMap = match?.filePath ? global.BUNDLER_CTX_MAP?.[match.filePath] : undefined; const module: BunextPageModule = await import(filePath); const Component = module.default as FC; const component = {{error.message}}; return { component, routeParams, module, bundledMap, serverRes: { responseOptions: { status: is404 ? 404 : 500, }, } as any, }; } catch { const DefaultNotFound: FC = () => (

{is404 ? "404 Not Found" : "500 Internal Server Error"}

{error.message}
); return { component: , routeParams, module: { default: DefaultNotFound }, bundledMap: undefined, serverRes: { responseOptions: { status: is404 ? 404 : 500, }, } as any, }; } }