Skip to content

Commit cecfd8b

Browse files
committed
custom handling error
1 parent aa4f0a4 commit cecfd8b

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

backend/src/api/controllers/user.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,25 @@ export async function sendVerificationEmail(
7070

7171
const userInfo = await UserDAL.getUser(uid, "request verification email");
7272

73-
const link = await admin.auth().generateEmailVerificationLink(email, {
74-
url:
75-
process.env.MODE === "dev"
76-
? "http://localhost:3000"
77-
: "https://monkeytype.com",
78-
});
73+
let link = "";
74+
try {
75+
link = await admin.auth().generateEmailVerificationLink(email, {
76+
url:
77+
process.env.MODE === "dev"
78+
? "http://localhost:3000"
79+
: "https://monkeytype.com",
80+
});
81+
} catch (e) {
82+
if (
83+
e.code === "auth/internal-error" &&
84+
e.message.includes("TOO_MANY_ATTEMPTS_TRY_LATER")
85+
) {
86+
// for some reason this error is not handled with a custom auth/ code, so we have to do it manually
87+
throw new MonkeyError(429, "Too many requests. Please try again later.");
88+
}
89+
throw e;
90+
}
91+
7992
await emailQueue.sendVerificationEmail(email, userInfo.name, link);
8093

8194
return new MonkeyResponse("Email sent");

0 commit comments

Comments
 (0)