Improve error handling for 2FA rate limit

This commit is contained in:
KernelDeimos 2024-05-06 16:35:35 -04:00
parent 7f3e2852c6
commit 429b7033a4
2 changed files with 34 additions and 21 deletions

View File

@ -195,31 +195,42 @@ async function UIWindowLogin(options){
new CodeEntryView({ new CodeEntryView({
_ref: me => code_entry = me, _ref: me => code_entry = me,
async [`property.value`] (value, { component }) { async [`property.value`] (value, { component }) {
const resp = await fetch(`${api_origin}/login/otp`, { let error_i18n_key = 'something_went_wrong';
method: 'POST', try {
headers: { const resp = await fetch(`${api_origin}/login/otp`, {
'Content-Type': 'application/json', method: 'POST',
}, headers: {
body: JSON.stringify({ 'Content-Type': 'application/json',
token: data.otp_jwt_token, },
code: value, body: JSON.stringify({
}), token: data.otp_jwt_token,
}); code: value,
}),
});
const next_data = await resp.json(); if ( resp.status === 429 ) {
error_i18n_key = 'confirm_code_generic_too_many_requests';
throw new Error('expected error');
}
const next_data = await resp.json();
if ( ! next_data.proceed ) {
error_i18n_key = 'confirm_code_generic_incorrect';
throw new Error('expected error');
}
if ( ! next_data.proceed ) {
component.set('error', i18n('confirm_code_generic_incorrect'));
component.set('is_checking_code', false); component.set('is_checking_code', false);
return;
data = next_data;
$(win).close();
p.resolve();
} catch (e) {
console.log('error object', e)
component.set('error', i18n(error_i18n_key));
component.set('is_checking_code', false);
} }
component.set('is_checking_code', false);
data = next_data;
$(win).close();
p.resolve();
} }
}), }),
new Button({ new Button({

View File

@ -50,6 +50,7 @@ const en = {
confirm_2fa_recovery: 'I have saved my recovery codes in a secure location', confirm_2fa_recovery: 'I have saved my recovery codes in a secure location',
confirm_account_for_free_referral_storage_c2a: 'Create an account and confirm your email address to receive 1 GB of free storage. Your friend will get 1 GB of free storage too.', confirm_account_for_free_referral_storage_c2a: 'Create an account and confirm your email address to receive 1 GB of free storage. Your friend will get 1 GB of free storage too.',
confirm_code_generic_incorrect: "Incorrect Code.", confirm_code_generic_incorrect: "Incorrect Code.",
confirm_code_generic_too_many_requests: "Too many requests. Please wait a few minutes.",
confirm_code_generic_submit: "Submit Code", confirm_code_generic_submit: "Submit Code",
confirm_code_generic_try_again: "Try Again", confirm_code_generic_try_again: "Try Again",
confirm_code_generic_title: "Enter Confirmation Code", confirm_code_generic_title: "Enter Confirmation Code",
@ -239,6 +240,7 @@ const en = {
signing_in: "Signing in…", signing_in: "Signing in…",
size: 'Size', size: 'Size',
skip: 'Skip', skip: 'Skip',
something_went_wrong: "Something went wrong.",
sort_by: 'Sort by', sort_by: 'Sort by',
start: 'Start', start: 'Start',
status: "Status", status: "Status",