diff --git a/pages/api/users/[id]/index.ts b/pages/api/users/[id]/index.ts index 50a54eb50..cc1775c83 100644 --- a/pages/api/users/[id]/index.ts +++ b/pages/api/users/[id]/index.ts @@ -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; diff --git a/pages/u/[identifier].tsx b/pages/u/[identifier].tsx index 3bc170f2d..f22c09953 100644 --- a/pages/u/[identifier].tsx +++ b/pages/u/[identifier].tsx @@ -171,22 +171,24 @@ export const getStaticPaths: GetStaticPaths = async () => { }; export const getStaticProps: GetStaticProps = 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; diff --git a/prisma/queries/getUserByIdentifier.ts b/prisma/queries/getUserByIdentifier.ts index 28936ee9a..d45ce2354 100644 --- a/prisma/queries/getUserByIdentifier.ts +++ b/prisma/queries/getUserByIdentifier.ts @@ -59,4 +59,5 @@ export const getUserByIdentifier = (identifier: string) => select: { id: true }, }, }, + rejectOnNotFound: true, });