Throw errors

pull/11421/merge^2
Sean Brydon 2023-09-14 12:27:36 +01:00
parent c1e63bcbda
commit eb04db9b26
2 changed files with 12 additions and 5 deletions

View File

@ -37,8 +37,12 @@ export default async function handler(req: RequestWithUsernameStatus, res: NextA
return selfhostedSignupHandler(req, res);
} catch (e) {
if (e instanceof HttpError) {
return res.status(e.statusCode).json({ message: e.message });
console.log("HTTPERROR");
res.status(e.statusCode).json({ message: e.message });
}
throw e;
console.log("INTERNAL SERVER ERROR");
res.status(500).json({ message: "Internal server error" });
} finally {
console.log("FINALLY - we have a log");
}
}

View File

@ -54,9 +54,12 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
throwIfTokenExpired(foundToken?.expires);
validateUsernameForTeam({ username, email, teamId: foundToken?.teamId });
} else {
const userValidation = await validateUsername(username, email);
if (!userValidation.isValid) {
return res.status(409).json({ message: "Username or email is already taken" });
const usernameAndEmailValidation = await validateUsername(username, email);
if (!usernameAndEmailValidation.isValid) {
throw new HttpError({
statusCode: 409,
message: "Username or email is already taken",
});
}
}