Skip to content

Commit

Permalink
refactor: add root error boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Aug 16, 2024
1 parent 56fa14e commit 5ccc44d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client';

import { ErrorBoundaryProps } from '@/shared/core/types';
import { InternalErrorResult } from '@/shared/components/internal-error-result';

const Error = (props: ErrorBoundaryProps) => {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="w-full max-w-2xl">
<InternalErrorResult showReset={false} {...props} />
</div>
</div>
);
};

export default Error;
11 changes: 9 additions & 2 deletions src/shared/components/internal-error-result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ const MESSAGE_TEXT =
'All shortcuts have disappeared. Screen. Mind. Both are blank';

interface Props extends Partial<ErrorBoundaryProps> {
showReset?: boolean;
onReset?: () => void;
}

export const InternalErrorResult = ({ onReset, reset }: Props) => {
export const InternalErrorResult = ({
showReset = true,
onReset,
reset,
}: Props) => {
const text = {
heading: HEADING_TEXT,
message: MESSAGE_TEXT,
Expand All @@ -32,12 +37,14 @@ export const InternalErrorResult = ({ onReset, reset }: Props) => {
if (onReset) onReset();
};

const action = showReset ? <ErrorActionButton onClick={onClick} /> : null;

return (
<ErrorAction
textContent={text}
imageProps={img}
classNames={classNames}
action={<ErrorActionButton onClick={onClick} />}
action={action}
/>
);
};

0 comments on commit 5ccc44d

Please sign in to comment.