Skip to content

Commit 0b51466

Browse files
[chore] handle offline case in +error.svelte
Co-authored-by: Rich Harris <hello@rich-harris.dev>
1 parent d2c6d4d commit 0b51466

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

src/routes/+error.svelte

+46-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,60 @@
11
<script>
2-
import { dev } from '$app/environment';
32
import { page } from '$app/stores';
3+
// we don't want to use <svelte:window bind:online> here, because we only care about the online
4+
// state when the page first loads
5+
let online = typeof navigator !== 'undefined' ? navigator.onLine : true;
46
</script>
57

6-
<div class="error">
7-
<div class="content">
8-
<h1>{$page.status}</h1>
8+
<svelte:head>
9+
<title>{$page.status}</title>
10+
</svelte:head>
911

10-
{#if dev && $page.error}
11-
<pre>{$page.error.stack}</pre>
12+
<div class="container">
13+
{#if $page.status === 404}
14+
<h1>Not found!</h1>
15+
{:else if online}
16+
<h1>Yikes!</h1>
17+
18+
{#if $page.error?.message}
19+
<p class="error">{$page.status}: {$page.error.message}</p>
1220
{/if}
13-
</div>
21+
22+
<p>Please try reloading the page.</p>
23+
24+
<p>
25+
If the error persists, please drop by <a href="https://svelte.dev/chat">Discord chatroom</a>
26+
and let us know, or raise an issue on
27+
<a href="https://github.com/sveltejs/svelte">GitHub</a>. Thanks!
28+
</p>
29+
{:else}
30+
<h1>It looks like you're offline</h1>
31+
32+
<p>Reload the page once you've found the internet.</p>
33+
{/if}
1434
</div>
1535

1636
<style>
17-
.error {
18-
display: flex;
19-
width: 100%;
20-
height: 100%;
21-
flex-direction: column;
22-
justify-content: center;
23-
align-items: center;
24-
padding: 2rem;
37+
.container {
38+
padding: 4rem;
39+
}
40+
h1,
41+
p {
42+
margin: 0 auto;
2543
}
26-
2744
h1 {
28-
font-weight: 400;
29-
font-size: 8rem;
30-
text-align: center;
45+
font-size: 2.8em;
46+
font-weight: 300;
47+
margin: 0;
48+
margin-bottom: 0.5em;
3149
}
32-
33-
pre {
34-
/* max-width: 40em; */
35-
font-size: 1.4rem;
50+
p {
51+
margin: 1em auto;
52+
}
53+
.error {
54+
background-color: #da106e;
55+
color: white;
56+
padding: 12px 16px;
57+
font: 600 16px/1.7 var(--sk-font);
58+
border-radius: 2px;
3659
}
3760
</style>

0 commit comments

Comments
 (0)