mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-07 19:55:46 -05:00
closes #255 getuserbyidentifier throw error
This commit is contained in:
@@ -12,9 +12,12 @@ const userHandler = async (
|
||||
return res.status(405).end();
|
||||
}
|
||||
|
||||
const user = await getUserByIdentifier(req.query.id as string);
|
||||
if (!user) return res.status(404).end();
|
||||
res.status(200).json(user);
|
||||
try {
|
||||
const user = await getUserByIdentifier(req.query.id as string);
|
||||
res.status(200).json(user!);
|
||||
} catch {
|
||||
res.status(404).end();
|
||||
}
|
||||
};
|
||||
|
||||
export default userHandler;
|
||||
|
||||
@@ -171,22 +171,24 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<Props> = async ({ params }) => {
|
||||
const user = await getUserByIdentifier(params!.identifier as string);
|
||||
try {
|
||||
const user = await getUserByIdentifier(params!.identifier as string);
|
||||
|
||||
if (!user) return { notFound: true };
|
||||
const peak = user!.player?.switchAccountId
|
||||
? await getPlayersPeak(user!.player.switchAccountId)
|
||||
: { peakXPowers: {}, peakLeaguePowers: {} };
|
||||
|
||||
const peak = user.player?.switchAccountId
|
||||
? await getPlayersPeak(user.player.switchAccountId)
|
||||
: { peakXPowers: {}, peakLeaguePowers: {} };
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
peakXPowers: peak.peakXPowers,
|
||||
peakLeaguePowers: peak.peakLeaguePowers,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
peakXPowers: peak.peakXPowers,
|
||||
peakLeaguePowers: peak.peakLeaguePowers,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
} catch (e) {
|
||||
return { notFound: true };
|
||||
}
|
||||
};
|
||||
|
||||
export default ProfilePage;
|
||||
|
||||
@@ -59,4 +59,5 @@ export const getUserByIdentifier = (identifier: string) =>
|
||||
select: { id: true },
|
||||
},
|
||||
},
|
||||
rejectOnNotFound: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user