31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { RefreshCw } from "lucide-react";
|
|
import { useT } from "@/components/I18n";
|
|
import { isStaleAction, reportStaleAction } from "@/components/StaleActionGuard";
|
|
|
|
/**
|
|
* PEP-324: the error boundary of every page. Before it a failed form action (most often a button of a
|
|
* page opened before an update) left the person with Next's «Application error». An unknown action is
|
|
* handed to StaleActionGuard (keep the text, say FORGE was updated, reload); any other error gets a
|
|
* plain screen — React still writes it to console.error, so it reaches «Ошибки из прода».
|
|
*/
|
|
export default function PageError({ error }: { error: Error & { digest?: string } }) {
|
|
const t = useT();
|
|
const stale = isStaleAction(error);
|
|
useEffect(() => {
|
|
if (stale) reportStaleAction();
|
|
}, [stale]);
|
|
if (stale) return null;
|
|
return (
|
|
<div role="alert" className="mx-auto flex max-w-lg flex-col items-start gap-3 p-8">
|
|
<p className="text-base font-medium">{t("Страница не открылась из-за ошибки.")}</p>
|
|
<p className="text-sm text-muted-foreground">{t("Обновите страницу или вернитесь назад.")}</p>
|
|
<button type="button" onClick={() => window.location.reload()} className="inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground">
|
|
<RefreshCw className="size-3.5" /> {t("Обновить страницу")}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|