1- import { Center , Stack } from "@mantine/core" ;
1+ import { Button , Center , Code , CopyButton , Stack } from "@mantine/core" ;
2+ import {
3+ useColorScheme ,
4+ useDocumentVisibility ,
5+ useNetwork ,
6+ useOrientation ,
7+ useOs ,
8+ useReducedMotion ,
9+ useViewportSize ,
10+ } from "@mantine/hooks" ;
11+ import { IconCheck , IconCopy } from "@tabler/icons-react" ;
12+ import dayjs from "dayjs" ;
13+ import { usePathname , useSearchParams } from "next/navigation" ;
214import { Activity , useEffect } from "react" ;
315
416import Logo from "@/features/layout/Logo" ;
517import ErrorAlert from "@/shared/components/alerts/ErrorAlert" ;
618import NextAnchor from "@/shared/components/NextAnchor" ;
19+ import useAuth from "@/shared/hooks/useAuth" ;
720
821export default function ErrorBoundary ( {
922 error,
@@ -14,6 +27,64 @@ export default function ErrorBoundary({
1427 withLogo ?: boolean ;
1528 href ?: string ;
1629} ) {
30+ const os = useOs ( ) ;
31+ const orientation = useOrientation ( ) ;
32+ const { isLoggedIn } = useAuth ( ) ;
33+ const pathname = usePathname ( ) ;
34+ const searchParams = useSearchParams ( ) ;
35+
36+ const { width, height } = useViewportSize ( ) ;
37+ const network = useNetwork ( ) ;
38+ const colorScheme = useColorScheme ( ) ;
39+ const reducedMotion = useReducedMotion ( ) ;
40+ const visibility = useDocumentVisibility ( ) ;
41+
42+ const debugText = `----- DEBUG START -----
43+
44+ Timestamp: ${ dayjs ( ) . toISOString ( ) }
45+
46+ --- ROUTING ---
47+ Pathname: ${ pathname }
48+ Search params: ${ searchParams ?. toString ( ) || "none" }
49+
50+ --- AUTH ---
51+ isLoggedIn: ${ isLoggedIn }
52+
53+ --- ERROR ---
54+ Name: ${ error . name }
55+ Message: ${ error . message }
56+ Digest: ${ error . digest ?? "n/a" }
57+ Stack: ${ error . stack ?? "n/a" }
58+
59+ --- UI ---
60+ OS: ${ os }
61+ Orientation: ${ orientation . type }
62+ Color scheme: ${ colorScheme }
63+ Reduced motion: ${ reducedMotion }
64+ Document visibility: ${ visibility }
65+
66+ --- VIEWPORT ---
67+ Size: ${ width } x ${ height }
68+ DPR: ${ typeof window !== "undefined" ? window . devicePixelRatio : "n/a" }
69+
70+ --- BROWSER ---
71+ User agent: ${ typeof navigator !== "undefined" ? navigator . userAgent : "n/a" }
72+ Language: ${ typeof navigator !== "undefined" ? navigator . language : "n/a" }
73+ Online: ${ typeof navigator !== "undefined" ? navigator . onLine : "n/a" }
74+ Cookies enabled: ${ typeof navigator !== "undefined" ? navigator . cookieEnabled : "n/a" }
75+
76+ --- NETWORK ---
77+ Online: ${ network . online }
78+ Effective type: ${ network . effectiveType ?? "unknown" }
79+ Downlink: ${ network . downlink ?? "unknown" }
80+ RTT: ${ network . rtt ?? "unknown" }
81+
82+ --- LOCATION ---
83+ Href: ${ typeof window !== "undefined" ? window . location . href : "n/a" }
84+ Referrer: ${ typeof document !== "undefined" ? document . referrer || "none" : "n/a" }
85+
86+ ------ DEBUG END ------` ;
87+
1788 useEffect ( ( ) => {
1889 console . error ( error ) ;
1990 } , [ error ] ) ;
@@ -23,8 +94,22 @@ export default function ErrorBoundary({
2394 { withLogo && < Logo variant = { "blue" } /> }
2495 < ErrorAlert title = { "Oisann! Her gikk noe veldig galt!" } >
2596 Du kan prøve å laste inn siden på nytt, eller gå tilbake til forsiden.
26- Ta kontakt på
[email protected] dersom problemet vedvarer!
97+ Ta kontakt på
[email protected] dersom problemet vedvarer! Kopier
98+ feilmeldingen under inn i e-posten, slik at vi enklere kan hjelpe deg.
2799 </ ErrorAlert >
100+ < CopyButton value = { debugText } >
101+ { ( { copied, copy } ) => (
102+ < Button
103+ leftSection = { copied ? < IconCheck /> : < IconCopy /> }
104+ color = { copied ? "teal" : "blue" }
105+ onClick = { copy }
106+ >
107+ Kopier feilmelding
108+ </ Button >
109+ ) }
110+ </ CopyButton >
111+
112+ < Code block > { debugText } </ Code >
28113 < Center >
29114 < Activity mode = { href ? "visible" : "hidden" } >
30115 < NextAnchor
0 commit comments