This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
"use client"
|
||||
|
||||
// The last boundary: the root layout itself threw, so there is no document, no stylesheet and no
|
||||
// provider of strings -- this file renders its own <html> and carries its own two languages, chosen
|
||||
// from the browser's. The server has already logged the error; this reports the browser's side.
|
||||
|
||||
import { useEffect } from "react"
|
||||
import { reportClientError } from "../src/observe/browser"
|
||||
|
||||
const STRINGS = {
|
||||
en: { title: "Something went wrong", body: "The app could not be shown. Try again.", retry: "Try again" },
|
||||
lt: {
|
||||
title: "Kažkas nepavyko",
|
||||
body: "Programos parodyti nepavyko. Bandykite dar kartą.",
|
||||
retry: "Bandyti dar kartą",
|
||||
},
|
||||
} as const
|
||||
|
||||
export default function GlobalError({ error, retry }: { error: Error & { digest?: string }; retry: () => void }) {
|
||||
useEffect(() => {
|
||||
reportClientError(error)
|
||||
}, [error])
|
||||
const locale = typeof navigator !== "undefined" && navigator.language.toLowerCase().startsWith("lt") ? "lt" : "en"
|
||||
const strings = STRINGS[locale]
|
||||
return (
|
||||
<html lang={locale}>
|
||||
<body>
|
||||
<main>
|
||||
<h1>{strings.title}</h1>
|
||||
<p role="alert">{strings.body}</p>
|
||||
<button type="button" onClick={retry}>
|
||||
{strings.retry}
|
||||
</button>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user