mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-07 19:38:09 +08:00
impr: notify user that captcha api failed to respond instead of throwing a server error
This commit is contained in:
parent
f929d65a6c
commit
316bbd33a6
1 changed files with 12 additions and 2 deletions
|
|
@ -40,8 +40,18 @@ import { addImportantLog, addLog, deleteUserLogs } from "../../dal/logs";
|
|||
import { sendForgotPasswordEmail as authSendForgotPasswordEmail } from "../../utils/auth";
|
||||
|
||||
async function verifyCaptcha(captcha: string): Promise<void> {
|
||||
if (!(await verify(captcha))) {
|
||||
throw new MonkeyError(422, "Captcha check failed");
|
||||
let verified = false;
|
||||
try {
|
||||
verified = await verify(captcha);
|
||||
} catch (e) {
|
||||
//fetch to recaptcha api can sometimes fail
|
||||
throw new MonkeyError(
|
||||
422,
|
||||
"Request to the Captcha API failed, please try again later"
|
||||
);
|
||||
}
|
||||
if (!verified) {
|
||||
throw new MonkeyError(422, "Captcha challenge failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue