Skip to content

Commit d2663de

Browse files
committed
fix(frontend): better 404 profile handling
1 parent 4b8a8ad commit d2663de

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

frontend/src/lib/components/ErrorPage.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import LucideArrowLeft from '~icons/lucide/arrow-left';
3+
24
export let status: number = 500;
35
export let error: { message?: string } | null = null;
46
@@ -20,4 +22,12 @@
2022
<p class="m-0 text-2xl font-bold text-lavender">{meaning}</p>
2123
</div>
2224
</header>
25+
26+
<button
27+
on:click={() => window.history.back()}
28+
class="inline-flex items-center gap-2 rounded-md bg-surface0/50 px-4 py-2 text-sm font-medium text-text hover:bg-surface0 cursor-pointer"
29+
>
30+
<LucideArrowLeft class="h-4 w-4" aria-hidden="true" />
31+
<span>Go Back</span>
32+
</button>
2333
</section>

frontend/src/routes/@[slug]/+page.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type { PageServerLoad } from './$types';
22
import type { ProfileResponse } from '$lib/types/profile';
33
import { createApi, ApiError } from '$lib/api/api';
4-
import { error } from '@sveltejs/kit';
54

65
export const load: PageServerLoad = async ({ fetch, params }) => {
7-
const loadProfile = async (): Promise<ProfileResponse> => {
6+
const loadProfile = async (): Promise<ProfileResponse | null> => {
87
try {
98
const api = createApi(fetch);
109
return await api.get<ProfileResponse>(`/page/profile/${params.slug}`);
1110
} catch (e) {
12-
console.error('Error loading profile page data:', e);
13-
const err = e as ApiError;
14-
throw error(err.status || 500, err.message);
11+
if (e instanceof ApiError && e.status === 404) {
12+
return null;
13+
}
14+
throw e;
1515
}
1616
};
1717

frontend/src/routes/@[slug]/+page.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343

4444
{#if deferred.showSkeleton}
4545
<ProfileSkeleton />
46+
{:else if deferred.data === null}
47+
<PageScaffold title="Not Found" showLastUpdated={false}>
48+
<EmptyState
49+
title="Profile not found"
50+
description="The user you're looking for doesn't exist :("
51+
className="mb-4"
52+
/>
53+
</PageScaffold>
4654
{:else if deferred.data}
4755
{@const profileData = deferred.data}
4856
<PageScaffold title="@{profileData.user.username}" showLastUpdated={false}>

0 commit comments

Comments
 (0)