|
| 1 | +<script lang="ts"> |
| 2 | + import { page } from '$app/state'; |
| 3 | + import Button from '$lib/components/ui/button/button.svelte'; |
| 4 | + import * as Alert from '$lib/components/ui/alert'; |
| 5 | + import IconAlertCircle from 'phosphor-icons-svelte/IconWarningCircleRegular.svelte'; |
| 6 | + import Spinner from '$lib/components/ui/spinner/spinner.svelte'; |
| 7 | + import { base } from '$app/paths'; |
| 8 | +
|
| 9 | + let { error: propError, status: propStatus } = $props<{ |
| 10 | + error?: string; |
| 11 | + status?: number; |
| 12 | + }>(); |
| 13 | +
|
| 14 | + let reload = $state(false); |
| 15 | +
|
| 16 | + let finalError = $derived(propError ?? page.error ?? 'error fetching error'); |
| 17 | +
|
| 18 | + let finalStatus = $derived(propStatus ?? page.status ?? 500); |
| 19 | +
|
| 20 | + let errorMessage = $derived(() => { |
| 21 | + if (typeof finalError === 'string') return finalError; |
| 22 | + return finalError?.message ?? 'error fetching error'; |
| 23 | + }); |
| 24 | +</script> |
| 25 | + |
| 26 | +<main |
| 27 | + class="absolute top-1/2 left-1/2 flex w-1/2 -translate-x-1/2 -translate-y-1/2 flex-col items-center gap-4" |
| 28 | +> |
| 29 | + <Alert.Root> |
| 30 | + <IconAlertCircle /> |
| 31 | + <Alert.Title>Oops! Something went wrong.</Alert.Title> |
| 32 | + <Alert.Description> |
| 33 | + <h1>Status: <span class="text-destructive">{finalStatus}</span></h1> |
| 34 | + <p>Error: <span class="text-destructive">{errorMessage()}</span></p> |
| 35 | + </Alert.Description> |
| 36 | + </Alert.Root> |
| 37 | + |
| 38 | + <ol class="mt-4 flex gap-2"> |
| 39 | + <Button href={base}>Go Home</Button> |
| 40 | + <Button onclick={() => window.history.back()}>Go Back</Button> |
| 41 | + <Button onclick={() => (window.location.reload(), (reload = true))} class="relative"> |
| 42 | + <Spinner |
| 43 | + class="absolute top-1/2 left-1/2 flex w-1/2 -translate-x-1/2 -translate-y-1/2 {reload |
| 44 | + ? 'opacity-100' |
| 45 | + : 'opacity-0'}" |
| 46 | + /> |
| 47 | + <span class={reload ? 'opacity-0' : 'opacity-100'}>Retry</span> |
| 48 | + </Button> |
| 49 | + </ol> |
| 50 | +</main> |
0 commit comments