Skip to content

Commit

Permalink
Check nested error boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbasa-elp committed Feb 24, 2024
1 parent 702b158 commit a2239fd
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { PropsWithChildren } from "react";
import {
isRouteErrorResponse,
Links,
Meta,
Scripts,
useRouteError,
} from "@remix-run/react";

export const ErrorBoundaryLayout: React.FC<
PropsWithChildren<{ className?: string }>
> = ({ children, className }) => {
const error = useRouteError();
const getTitle = () => {
if (isRouteErrorResponse(error)) {
if (error.status === 404) return "Not Found";
return "Something went wrong";
}
};
return (
<html>
<head>
<title>{getTitle()}</title>
<Meta />
<Links />
</head>
<body className={className}>
{children}
<Scripts />
</body>
</html>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { isRouteErrorResponse, useRouteError } from "@remix-run/react";

export const BuildErrorBoundary = () => {
const error = useRouteError();

const getStatus = () => {
if (isRouteErrorResponse(error)) {
return error.status;
}

return 500;
};

const status = getStatus();

return (
<div className="my-6 p-2 rounded-lg text-center">
{status === 404 ? <NotFound /> : <Runtime />}
</div>
);
};

function NotFound() {
return <p className="text-white text-sm">Page not found...</p>;
}

function Runtime() {
return <p className="text-red-500 text-sm">Ups! Something went wrong...</p>;
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { PipelineBuilder as page, meta } from "./page";
export { BuildErrorBoundary as ErrorBoundary } from "./errorBoundary";
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export async function loader(args: LoaderFunctionArgs) {
const pipeline = await pipelineApi.getAliasedPipeline(
params.organizationId,
params.pipelineId,
aliasId,
aliasId
);

const blocks = pipeline.config.blocks.map((block) => ({
...block,
block_type: blockTypes.data.find(
(blockType) => blockType.type === block.type,
(blockType) => blockType.type === block.type
),
}));

Expand Down
15 changes: 4 additions & 11 deletions apps/web-remix/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "./tailwind.css";
import { GlobalNotFound } from "~/components/errorBoundaries/GlobalNotFound";
import { GlobalRuntime } from "~/components/errorBoundaries/GlobalRuntime";
import { PageProgress } from "~/components/progressBar/PageProgress";
import { ErrorBoundaryLayout } from "~/components/errorBoundaries/ErrorBoundaryLayout";

Modal.setAppElement("#_root");

Expand Down Expand Up @@ -74,16 +75,8 @@ export function ErrorBoundary() {
};

return (
<html>
<head>
<title>Oh no!</title>
<Meta />
<Links />
</head>
<body className="bg-neutral-950 text-white">
{renderErrorUi()}
<Scripts />
</body>
</html>
<ErrorBoundaryLayout className="bg-neutral-950 text-white">
{renderErrorUi()}
</ErrorBoundaryLayout>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { page as default, meta } from "~/components/pages/pipelines/build";
export {
page as default,
meta,
ErrorBoundary,
} from "~/components/pages/pipelines/build";
export {
loader,
action,
Expand Down

0 comments on commit a2239fd

Please sign in to comment.