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,6 +195,8 @@ async function UIWindowLogin(options){
new CodeEntryView({
_ref: me => code_entry = me,
async [`property.value`] (value, { component }) {
let error_i18n_key = 'something_went_wrong';
try {
const resp = await fetch(`${api_origin}/login/otp`, {
method: 'POST',
headers: {
@ -206,12 +208,16 @@ async function UIWindowLogin(options){
}),
});
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 ) {
component.set('error', i18n('confirm_code_generic_incorrect'));
component.set('is_checking_code', false);
return;
error_i18n_key = 'confirm_code_generic_incorrect';
throw new Error('expected error');
}
component.set('is_checking_code', false);
@ -220,6 +226,11 @@ async function UIWindowLogin(options){
$(win).close();
p.resolve();
} catch (e) {
console.log('error object', e)
component.set('error', i18n(error_i18n_key));
component.set('is_checking_code', false);
}
}
}),
new Button({

View File

@ -50,6 +50,7 @@ const en = {
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_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_try_again: "Try Again",
confirm_code_generic_title: "Enter Confirmation Code",
@ -239,6 +240,7 @@ const en = {
signing_in: "Signing in…",
size: 'Size',
skip: 'Skip',
something_went_wrong: "Something went wrong.",
sort_by: 'Sort by',
start: 'Start',
status: "Status",