feat: redirect /[username] to /@[username] if no page matches

This commit is contained in:
Sam 2023-03-28 10:02:20 +02:00
parent 56c0d40a11
commit c60429d884
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import { ErrorCode, type APIError, type User } from "$lib/api/entities";
import { apiFetch } from "$lib/api/fetch";
import { error, redirect } from "@sveltejs/kit";
export const load = async ({ params }) => {
try {
const resp = await apiFetch<User>(`/users/${params.username}`, {
method: "GET",
});
throw redirect(303, `/@${resp.name}`);
} catch (e) {
if ((e as APIError).code === ErrorCode.UserNotFound) {
throw error(404, (e as APIError).message);
}
throw e;
}
};

View File

@ -0,0 +1 @@
<h1>Page not found</h1>