Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add styled error pages #patch #39

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>%sveltekit.error.message%</title>
<link rel="stylesheet" href="/index.css" />
</head>
<body>
<main class="mx-auto flex h-full w-full max-w-3xl flex-col items-center justify-center px-2">
<h1 class="scroll-m-20 text-4xl font-extrabold tracking-tight">
<small class="text-muted-foreground">%sveltekit.status%</small>
%sveltekit.error.message%
</h1>

<a href="/">Home</a>
</main>
</body>

<style>
body {
/* bg-slate-900 */
background-color: rgb(2, 8, 23);
color: #fff;
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Open Sans',
'Helvetica Neue',
sans-serif;
}

html,
body {
height: 100%;
padding: 0;
margin: 0;
}

main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100%;
}

h1 {
font-size: 2.25rem;
font-weight: 800;
margin: 0;
}

small {
color: rgb(148, 163, 184);
font-size: 1.8rem;
}

a {
margin-top: 1.5rem;
color: #fff;
width: fit-content;
text-decoration: none;
font-size: 1rem;
}
</style>
</html>
10 changes: 9 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { auth } from '$lib/server/auth/lucia';
import { getApiKeyBySecret } from '$lib/server/database/handlers/api';
import { error, type Handle } from '@sveltejs/kit';
import { error, type Handle, type HandleServerError } from '@sveltejs/kit';
import { nanoid } from 'nanoid';

export const handle: Handle = async ({ event, resolve }) => {
if (event.url.pathname.startsWith('/api')) {
Expand All @@ -24,3 +25,10 @@ export const handle: Handle = async ({ event, resolve }) => {

return await resolve(event);
};

export const handleError: HandleServerError = async ({ message }) => {
return {
message,
errorId: nanoid()
};
};
18 changes: 18 additions & 0 deletions src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
import '../app.pcss';
import { page } from '$app/stores';
import Button from '$lib/components/ui/button/button.svelte';
</script>

<svelte:head>
<title>{$page.error?.message ?? 'unknown error'}</title>
</svelte:head>

<main class="mx-auto flex h-full w-full max-w-3xl flex-col items-center justify-center px-2">
<h1 class="scroll-m-20 text-4xl font-extrabold tracking-tight">
<small class="text-muted-foreground">{$page.status}</small>
{$page.error?.message ?? 'unknown error'}
</h1>

<Button variant="ghost" href="/" class="mt-4">Home</Button>
</main>
10 changes: 0 additions & 10 deletions src/routes/auth/+error.svelte

This file was deleted.

Loading