Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

handle error when project id not found

Oleg Isonen6e28fd9f6439
diff --git a/app/routes/designer/$id.tsx b/app/routes/designer/$id.tsx
index 497f460a42..35d74b11dd 100644
--- a/app/routes/designer/$id.tsx
+++ b/app/routes/designer/$id.tsx
@@ -9,6 +9,9 @@ export { links };
export const loader: LoaderFunction = async ({ params }) => {
if (params.id === undefined) throw new Error("Project id undefined");
const project = await db.project.loadById(params.id);
+ if (project === null) {
+ return { errors: `Project "${params.id}" not found` };
+ }
return { config, project };
};
@@ -17,9 +20,16 @@ type Data = {
project: Project;
};
+type Error = {
+ errors: "string";
+};
+
const DesignerRoute = () => {
- const { config, project } = useLoaderData<Data>();
- return <Designer config={config} project={project} />;
+ const data = useLoaderData<Data | Error>();
+ if ("errors" in data) {
+ return <p>{data.errors}</p>;
+ }
+ return <Designer {...data} />;
};
export default DesignerRoute;