mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
custom handling error
This commit is contained in:
parent
aa4f0a41f3
commit
cecfd8b7b5
|
@ -70,12 +70,25 @@ export async function sendVerificationEmail(
|
|||
|
||||
const userInfo = await UserDAL.getUser(uid, "request verification email");
|
||||
|
||||
const link = await admin.auth().generateEmailVerificationLink(email, {
|
||||
url:
|
||||
process.env.MODE === "dev"
|
||||
? "http://localhost:3000"
|
||||
: "https://monkeytype.com",
|
||||
});
|
||||
let link = "";
|
||||
try {
|
||||
link = await admin.auth().generateEmailVerificationLink(email, {
|
||||
url:
|
||||
process.env.MODE === "dev"
|
||||
? "http://localhost:3000"
|
||||
: "https://monkeytype.com",
|
||||
});
|
||||
} catch (e) {
|
||||
if (
|
||||
e.code === "auth/internal-error" &&
|
||||
e.message.includes("TOO_MANY_ATTEMPTS_TRY_LATER")
|
||||
) {
|
||||
// for some reason this error is not handled with a custom auth/ code, so we have to do it manually
|
||||
throw new MonkeyError(429, "Too many requests. Please try again later.");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
await emailQueue.sendVerificationEmail(email, userInfo.name, link);
|
||||
|
||||
return new MonkeyResponse("Email sent");
|
||||
|
|
Loading…
Reference in a new issue