Throw errors
parent
c1e63bcbda
commit
eb04db9b26
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue