-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruster opp logging og feilhåndtering
* fikser next-logger * har global feilside (ingen flere hvite "unhandled client exceptions"-skjermer) * har ordentlig 404-feilside * splitter layout inn i locale/no locale (så jeg kan ha error routes)
- Loading branch information
Showing
21 changed files
with
242 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import React, {useEffect} from "react"; | ||
import dynamic from "next/dynamic"; | ||
import {BASE_PATH} from "../../../lib/constants.ts"; | ||
import {configureLogger} from "@navikt/next-logger"; | ||
import {initAmplitude} from "../../../lib/amplitude/Amplitude.tsx"; | ||
|
||
const App = dynamic(() => import("../../../app.tsx"), {ssr: false}); | ||
|
||
export function ClientOnly() { | ||
configureLogger({basePath: BASE_PATH}); | ||
useEffect(() => { | ||
initAmplitude(); | ||
}, []); | ||
|
||
return <App />; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,26 @@ | ||
import {fetchDecoratorReact} from "@navikt/nav-dekoratoren-moduler/ssr"; | ||
import Script from "next/script"; | ||
import {DECORATOR_SETTINGS} from "../../decoratorSettings.tsx"; | ||
import {Driftsmeldinger} from "../../lib/driftsmeldinger/Driftsmeldinger.tsx"; | ||
import {notFound} from "next/navigation"; | ||
import {isSupportedLanguage} from "../../lib/i18n/common.ts"; | ||
import {getMessages} from "next-intl/server"; | ||
import {NextIntlClientProvider} from "next-intl"; | ||
import "../../index.css"; | ||
import {DigisosContextProvider} from "../../lib/providers/DigisosContextProvider.tsx"; | ||
import {NextIntlClientProvider} from "next-intl"; | ||
import {getMessages} from "next-intl/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export default async function RootLayout({ | ||
export default async function Layout({ | ||
children, | ||
params, | ||
}: { | ||
children: React.ReactNode; | ||
params: Promise<{locale: string}>; | ||
}) { | ||
const {locale} = await params; | ||
if (!isSupportedLanguage(locale)) notFound(); | ||
|
||
const Decorator = await fetchDecoratorReact({ | ||
...DECORATOR_SETTINGS, | ||
params: {...DECORATOR_SETTINGS.params, language: locale}, | ||
}); | ||
|
||
const {locale: localeParam} = await params; | ||
const messages = await getMessages(); | ||
|
||
// locale blir hentet via middleware.ts, | ||
// og html lang leses (som document.documentElement.lang) av både analytics og klientside i18n | ||
const locale = isSupportedLanguage(localeParam) ? localeParam : "nb"; | ||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<title>Søknad om økonomisk sosialhjelp</title> | ||
<Decorator.HeadAssets /> | ||
</head> | ||
<body> | ||
<Decorator.Header /> | ||
<Driftsmeldinger /> | ||
<div id="root" className={"bg-digisosGronnBakgrunn"} role={"none"}> | ||
<NextIntlClientProvider messages={messages}> | ||
<DigisosContextProvider>{children}</DigisosContextProvider> | ||
</NextIntlClientProvider> | ||
</div> | ||
<Decorator.Footer /> | ||
<Decorator.Scripts loader={Script} /> | ||
</body> | ||
</html> | ||
<NextIntlClientProvider messages={messages} locale={locale}> | ||
<DigisosContextProvider locale={locale}>{children}</DigisosContextProvider> | ||
</NextIntlClientProvider> | ||
); | ||
} | ||
|
||
export async function generateStaticParams() { | ||
return [{locale: "nb"}, {locale: "nn"}, {locale: "en"}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client"; | ||
|
||
import TekniskFeil from "../sider/feilsider/TekniskFeil.tsx"; | ||
import {logger} from "@navikt/next-logger"; | ||
import {logError} from "../lib/log/loggerUtils.ts"; | ||
import {useEffect} from "react"; | ||
import {faro} from "@grafana/faro-react"; | ||
|
||
export const ErrorComponent = ({error, reset}: {error: Error; reset: () => void}) => { | ||
if (faro.api) faro.api.pushError(error); | ||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_DIGISOS_ENV === "localhost") { | ||
logger.error( | ||
{errorMessage: error.message, referrer: document.referrer, location: document.location.href}, | ||
`En bruker har sett TekniskFeil` | ||
); | ||
logError(`Viser feilside, error, referrer: ${document.referrer}`); | ||
} | ||
}, [error]); | ||
return <TekniskFeil error={error} reset={reset} />; | ||
}; | ||
|
||
export default ErrorComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import {configureLogger, logger} from "@navikt/next-logger"; | ||
import Cookie from "js-cookie"; | ||
import {BASE_PATH, DECORATOR_LANG_COOKIE} from "../lib/constants.ts"; | ||
import {isSupportedLanguage} from "../lib/i18n/common.ts"; | ||
import {AbstractIntlMessages, NextIntlClientProvider} from "next-intl"; | ||
import TekniskFeil from "../sider/feilsider/TekniskFeil.tsx"; | ||
import {useEffect, useState} from "react"; | ||
|
||
export default function GlobalError({error, reset}: {error: Error & {digest?: string}; reset: () => void}) { | ||
configureLogger({basePath: BASE_PATH, apiPath: `${BASE_PATH}/api`}); | ||
|
||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_DIGISOS_ENV !== "localhost") | ||
logger.error(`En bruker har sett GlobalError, error: ${error} referrer: ${document.referrer}`); | ||
}, [error]); | ||
const langCookie = Cookie.get(DECORATOR_LANG_COOKIE); | ||
const locale = langCookie && isSupportedLanguage(langCookie) ? langCookie : "nb"; | ||
const [messages, setMessages] = useState<AbstractIntlMessages | null>(); | ||
import(`../../messages/${locale}.json`).then((module) => module.default).then(setMessages); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<title>Søknad om økonomisk sosialhjelp</title> | ||
</head> | ||
<body> | ||
<div id="root" className={"bg-digisosGronnBakgrunn"} role={"none"}> | ||
{messages && ( | ||
<NextIntlClientProvider messages={messages} locale={locale}> | ||
<TekniskFeil error={error} reset={reset} /> | ||
</NextIntlClientProvider> | ||
)} | ||
</div> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {fetchDecoratorReact} from "@navikt/nav-dekoratoren-moduler/ssr"; | ||
import Script from "next/script"; | ||
import {DECORATOR_SETTINGS} from "../decoratorSettings.tsx"; | ||
import {isSupportedLanguage} from "../lib/i18n/common.ts"; | ||
import {getMessages} from "next-intl/server"; | ||
import {NextIntlClientProvider} from "next-intl"; | ||
import "../index.css"; | ||
import {cookies} from "next/headers"; | ||
import {DECORATOR_LANG_COOKIE} from "../lib/constants.ts"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export default async function RootLayout({children}: {children: React.ReactNode}) { | ||
const jar = await cookies(); | ||
const cookie = jar.get(DECORATOR_LANG_COOKIE)?.value; | ||
const locale = cookie && isSupportedLanguage(cookie) ? cookie : "nb"; | ||
|
||
const Decorator = await fetchDecoratorReact({ | ||
...DECORATOR_SETTINGS, | ||
params: {...DECORATOR_SETTINGS.params, language: locale}, | ||
}); | ||
|
||
const messages = await getMessages(); | ||
// locale blir hentet via middleware.ts, | ||
// og html lang leses (som document.documentElement.lang) av både analytics og klientside i18n | ||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<title>Søknad om økonomisk sosialhjelp</title> | ||
<Decorator.HeadAssets /> | ||
</head> | ||
<body> | ||
<Decorator.Header /> | ||
<div id="root" className={"bg-digisosGronnBakgrunn"} role={"none"}> | ||
<NextIntlClientProvider messages={messages} locale={locale}> | ||
{children} | ||
</NextIntlClientProvider> | ||
</div> | ||
<Decorator.Footer /> | ||
<Decorator.Scripts loader={Script} /> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use client"; | ||
|
||
import IkkeFunnet from "../sider/feilsider/IkkeFunnet.tsx"; | ||
|
||
const NotFound = () => { | ||
return ( | ||
<div className={"grow bg-white flex-col flex"}> | ||
<IkkeFunnet /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NotFound; |
Oops, something went wrong.