diff --git a/src/UI/UIWindowLogin.js b/src/UI/UIWindowLogin.js index ce7fb3ff..f60a8ab5 100644 --- a/src/UI/UIWindowLogin.js +++ b/src/UI/UIWindowLogin.js @@ -195,31 +195,42 @@ async function UIWindowLogin(options){ new CodeEntryView({ _ref: me => code_entry = me, async [`property.value`] (value, { component }) { - const resp = await fetch(`${api_origin}/login/otp`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - token: data.otp_jwt_token, - code: value, - }), - }); + let error_i18n_key = 'something_went_wrong'; + try { + const resp = await fetch(`${api_origin}/login/otp`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + 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); - 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({ diff --git a/src/i18n/translations/en.js b/src/i18n/translations/en.js index 45a27dee..edee5410 100644 --- a/src/i18n/translations/en.js +++ b/src/i18n/translations/en.js @@ -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",