Add retries to page component function error. Reload for all 404 pages
This commit is contained in:
@@ -5,6 +5,7 @@ import _ from "lodash";
|
||||
import { log } from "../../../utils/log";
|
||||
import grabPageModules from "./grab-page-modules";
|
||||
import grabPageCombinedServerRes from "./grab-page-combined-server-res";
|
||||
import fullRebuild from "../full-rebuild";
|
||||
|
||||
class NotFoundError extends Error {
|
||||
status = 404;
|
||||
@@ -19,17 +20,22 @@ type Params = {
|
||||
req?: Request;
|
||||
file_path?: string;
|
||||
debug?: boolean;
|
||||
retry?: boolean;
|
||||
return_server_res_only?: boolean;
|
||||
skip_server_res?: boolean;
|
||||
};
|
||||
|
||||
export default async function grabPageComponent({
|
||||
req,
|
||||
file_path: passed_file_path,
|
||||
debug,
|
||||
return_server_res_only,
|
||||
skip_server_res,
|
||||
}: Params): Promise<GrabPageComponentRes> {
|
||||
export default async function grabPageComponent(
|
||||
params: Params,
|
||||
): Promise<GrabPageComponentRes> {
|
||||
const {
|
||||
req,
|
||||
file_path: passed_file_path,
|
||||
debug,
|
||||
return_server_res_only,
|
||||
skip_server_res,
|
||||
} = params;
|
||||
|
||||
const url = req?.url ? new URL(req.url) : undefined;
|
||||
const router = global.ROUTER;
|
||||
|
||||
@@ -101,6 +107,8 @@ export default async function grabPageComponent({
|
||||
skip_server_res,
|
||||
});
|
||||
|
||||
global.IS_404_PAGE = false;
|
||||
|
||||
return {
|
||||
component,
|
||||
serverRes,
|
||||
@@ -108,6 +116,7 @@ export default async function grabPageComponent({
|
||||
module,
|
||||
bundledMap,
|
||||
root_module,
|
||||
success: true,
|
||||
};
|
||||
} catch (error: any) {
|
||||
const is404 =
|
||||
@@ -115,7 +124,29 @@ export default async function grabPageComponent({
|
||||
error?.name === "NotFoundError" ||
|
||||
error?.status === 404;
|
||||
|
||||
if (!is404) {
|
||||
if (!params.retry) {
|
||||
while (global.REBUILD_RETRIES < 2) {
|
||||
global.REBUILD_RETRIES = global.REBUILD_RETRIES + 1;
|
||||
|
||||
await fullRebuild();
|
||||
await Bun.sleep(200);
|
||||
const component_retried = await grabPageComponent({
|
||||
...params,
|
||||
retry: true,
|
||||
});
|
||||
|
||||
if (component_retried.success) {
|
||||
global.REBUILD_RETRIES = 0;
|
||||
return component_retried;
|
||||
}
|
||||
}
|
||||
|
||||
global.REBUILD_RETRIES = 0;
|
||||
}
|
||||
|
||||
if (is404) {
|
||||
global.IS_404_PAGE = true;
|
||||
} else {
|
||||
log.error(`Error Grabbing Page Component: ${error.message}`);
|
||||
log.error(`Page: ${passed_file_path || url?.pathname}`);
|
||||
}
|
||||
@@ -128,34 +159,3 @@ export default async function grabPageComponent({
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// let root_module: any;
|
||||
|
||||
// if (root_file) {
|
||||
// if (isDevelopment()) {
|
||||
// root_module = await grabFilePathModule({
|
||||
// file_path: root_file,
|
||||
// });
|
||||
// } else {
|
||||
// root_module = root_file ? await import(root_file) : undefined;
|
||||
// }
|
||||
// }
|
||||
|
||||
// const RootComponent = root_module?.default as FC<any> | undefined;
|
||||
|
||||
// let module: BunextPageModule;
|
||||
|
||||
// if (isDevelopment()) {
|
||||
// module = await grabFilePathModule({ file_path });
|
||||
// } else {
|
||||
// module = await import(file_path);
|
||||
// }
|
||||
|
||||
// const Component = main_module.default as FC<any>;
|
||||
// const component = RootComponent ? (
|
||||
// <RootComponent {...serverRes}>
|
||||
// <Component {...serverRes} />
|
||||
// </RootComponent>
|
||||
// ) : (
|
||||
// <Component {...serverRes} />
|
||||
// );
|
||||
|
||||
Reference in New Issue
Block a user