fix: show 404 page if user cannot be found
This commit is contained in:
parent
7d8bb1023e
commit
2f66f94390
3 changed files with 30 additions and 10 deletions
|
@ -1,10 +1,22 @@
|
|||
import { apiFetch } from "$lib/api/fetch";
|
||||
import type { Member } from "$lib/api/entities";
|
||||
import { ErrorCode, type APIError, type Member } from "$lib/api/entities";
|
||||
import { error } from "@sveltejs/kit";
|
||||
|
||||
export const load = async ({ params }) => {
|
||||
const resp = await apiFetch<Member>(`/users/${params.username}/members/${params.memberName}`, {
|
||||
method: "GET",
|
||||
});
|
||||
try {
|
||||
const resp = await apiFetch<Member>(`/users/${params.username}/members/${params.memberName}`, {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
return resp;
|
||||
return resp;
|
||||
} catch (e) {
|
||||
if (
|
||||
(e as APIError).code === ErrorCode.UserNotFound ||
|
||||
(e as APIError).code === ErrorCode.MemberNotFound
|
||||
) {
|
||||
throw error(404, (e as APIError).message);
|
||||
}
|
||||
|
||||
throw error(500, (e as APIError).message);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue