A bit of error handling I guess

This commit is contained in:
Tiago Ribeiro
2024-09-08 18:54:44 +01:00
parent d5769c2cb9
commit 49e8237e99
2 changed files with 7 additions and 1 deletions

View File

@@ -141,7 +141,11 @@ export default function UserCreator({user, users, permissions, onFinish}: Props)
setType("student");
setPosition(undefined);
})
.catch(() => toast.error("Something went wrong! Please try again later!"))
.catch((error) => {
const data = error?.response?.data;
if (!!data?.message) return toast.error(data.message);
toast.error("Something went wrong! Please try again later!");
})
.finally(() => setIsLoading(false));
};

View File

@@ -218,6 +218,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
return res.status(200).json({ok: true});
})
.catch((error) => {
if (error.code.includes("email-already-in-use")) return res.status(403).json({error, message: "E-mail is already in the platform."});
console.log(`Failing - ${email}`);
console.log(error);
return res.status(401).json({error});