mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 05:07:46 +00:00
fix: handle not found errors for Mii and User in API responses
This commit is contained in:
parent
d58054a587
commit
d5b488a5c9
4 changed files with 12 additions and 4 deletions
|
|
@ -34,5 +34,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
|
|||
},
|
||||
});
|
||||
|
||||
if (!mii) return NextResponse.json({ error: "Mii not found" }, { status: 404 });
|
||||
|
||||
return NextResponse.json(mii);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,5 +21,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
|
|||
},
|
||||
});
|
||||
|
||||
if (!user) return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
|
||||
return NextResponse.json(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ export default function MiiPage() {
|
|||
return res.json();
|
||||
})
|
||||
.then((data) => {
|
||||
if (!data) throw new Error("Mii not found");
|
||||
|
||||
setMii(data);
|
||||
setLoading(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ export default function ProfileLayout() {
|
|||
return res.json();
|
||||
})
|
||||
.then((data) => {
|
||||
if (!data) throw new Error("Profile not found");
|
||||
|
||||
setUser(data);
|
||||
setLoading(false);
|
||||
})
|
||||
|
|
@ -42,11 +44,11 @@ export default function ProfileLayout() {
|
|||
return <div className="p-6 text-center">Loading...</div>;
|
||||
}
|
||||
|
||||
const currentUser = user ?? $session?.user;
|
||||
const sessionUserId = $session?.user?.id ? Number($session.user.id) : null;
|
||||
const page = location.pathname;
|
||||
const isAdmin = currentUser?.id === Number(import.meta.env.VITE_ADMIN_USER_ID);
|
||||
const isContributor = import.meta.env.VITE_CONTRIBUTORS_USER_IDS?.split(",").includes(user?.id);
|
||||
const isOwnProfile = currentUser?.id === user?.id;
|
||||
const isAdmin = sessionUserId === Number(import.meta.env.VITE_ADMIN_USER_ID);
|
||||
const isContributor = import.meta.env.VITE_CONTRIBUTORS_USER_IDS?.split(",").includes(String(user?.id));
|
||||
const isOwnProfile = sessionUserId === user?.id;
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue