closes #255 getuserbyidentifier throw error

This commit is contained in:
Kalle (Sendou)
2021-01-21 10:20:27 +02:00
parent 81b0ed5a07
commit d37ffbf8b5
3 changed files with 23 additions and 17 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -59,4 +59,5 @@ export const getUserByIdentifier = (identifier: string) =>
select: { id: true },
},
},
rejectOnNotFound: true,
});