diff --git a/dev/App/User.js b/dev/App/User.js index f018ccf55..cc23c5794 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -5,7 +5,6 @@ import { isPosNumeric, delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUs import { Capa, - Notification, Scope } from 'Common/Enums'; @@ -179,13 +178,13 @@ class AppUser extends AbstractApp { MessageUserStore.listError(''); Remote.messageList( (iError, oData, bCached) => { - if (!iError && oData && oData.Result) { + if (iError) { + if (Notification.RequestAborted !== iError) { + MessageUserStore.list([]); + MessageUserStore.listError(getNotification(iError)); + } + } else { MessageUserStore.setMessageList(oData, bCached); - } else if (Remote.ABORT !== iError) { - MessageUserStore.list([]); - MessageUserStore.listError( - getNotification((oData && oData.ErrorCode) || Notification.CantGetMessageList) - ); } MessageUserStore.listLoading(false); }, @@ -273,17 +272,15 @@ class AppUser extends AbstractApp { } moveOrDeleteResponseHelper(iError, oData) { - if (!iError && FolderUserStore.currentFolder()) { - if (oData && isArray(oData.Result) && 2 === oData.Result.length) { + if (iError) { + setFolderHash(FolderUserStore.currentFolderFullNameRaw(), ''); + alert(getNotification(iError)); + } else if (FolderUserStore.currentFolder()) { + if (isArray(oData.Result) && 2 === oData.Result.length) { setFolderHash(oData.Result[0], oData.Result[1]); } else { setFolderHash(FolderUserStore.currentFolderFullNameRaw(), ''); - - if (oData && [Notification.CantMoveMessage, Notification.CantCopyMessage].includes(oData.ErrorCode)) { - alert(getNotification(oData.ErrorCode)); - } } - this.reloadMessageList(!MessageUserStore.list.length); this.quotaDebounce(); } @@ -763,7 +760,7 @@ class AppUser extends AbstractApp { autocompleteCallback( data.Result.map(item => (item && item[0] ? new EmailModel(item[0], item[1]) : null)).filter(v => v) ); - } else if (Remote.ABORT !== iError) { + } else if (Notification.RequestAborted !== iError) { autocompleteCallback([]); } }, query); diff --git a/dev/Common/Enums.js b/dev/Common/Enums.js index 49cc42a1e..84b7f5598 100644 --- a/dev/Common/Enums.js +++ b/dev/Common/Enums.js @@ -77,6 +77,9 @@ export const SaveSettingsStep = { * @enum {number} */ export const Notification = { + RequestError: 1, + RequestAborted: 2, + InvalidToken: 101, AuthError: 102, ConnectionError: 104, diff --git a/dev/Common/Translator.js b/dev/Common/Translator.js index 0fff7abf4..63bcdd4d6 100644 --- a/dev/Common/Translator.js +++ b/dev/Common/Translator.js @@ -92,29 +92,17 @@ function getNotificationMessage(code) { * @param {*=} defCode = null * @returns {string} */ -export function getNotification(code, message = '', defCode = null) { +export function getNotification(code, message = '', defCode = 0) { code = parseInt(code, 10) || 0; if (Notification.ClientViewError === code && message) { return message; } - defCode = defCode ? parseInt(defCode, 10) || 0 : 0; return getNotificationMessage(code) - || getNotificationMessage(defCode) + || getNotificationMessage(parseInt(defCode, 10)) || ''; } -/** - * @param {object} response - * @param {number} defCode = Notification.UnknownNotification - * @returns {string} - */ -export function getNotificationFromResponse(response, defCode = Notification.UnknownNotification) { - return response && response.ErrorCode - ? getNotification(parseInt(response.ErrorCode, 10) || defCode, response.ErrorMessage || '') - : getNotification(defCode); -} - /** * @param {*} code * @returns {string} diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index 0e39f2802..631c5fc1b 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -32,11 +32,9 @@ checkResponseError = data => { ) { ++iJsonErrorCount; } - if (window.rl && (data.ClearAuth || data.Logout || 7 < iJsonErrorCount)) { + if (data.ClearAuth || data.Logout || 7 < iJsonErrorCount) { rl.hash.clear(); - if (!data.ClearAuth) { - rl.logoutReload(); - } + data.ClearAuth || rl.logoutReload(); } } }, @@ -116,10 +114,16 @@ export class AbstractFetchRemote } if (!iError && data) { +/* + if (sAction !== data.Action) { + console.log(sAction + ' !== ' + data.Action); + } +*/ if (data.Result) { iJsonErrorCount = iTokenErrorCount = 0; } else { checkResponseError(data); + iError = data.ErrorCode || Notification.UnknownError } } diff --git a/dev/Settings/Admin/Packages.js b/dev/Settings/Admin/Packages.js index 86c2b6669..f2d04f6c1 100644 --- a/dev/Settings/Admin/Packages.js +++ b/dev/Settings/Admin/Packages.js @@ -35,14 +35,11 @@ export class PackagesAdminSettings { requestHelper(packageToRequest, install) { return (iError, data) => { - if (iError || !data || !data.Result) { - if (data && data.ErrorCode) { - this.packagesError(getNotification(data.ErrorCode)); - } else { - this.packagesError( - getNotification(install ? Notification.CantInstallPackage : Notification.CantDeletePackage) - ); - } + if (iError) { + this.packagesError( + getNotification(install ? Notification.CantInstallPackage : Notification.CantDeletePackage) +// ':\n' + getNotification(iError); + ); } PackageAdminStore.forEach(item => { @@ -52,7 +49,7 @@ export class PackagesAdminSettings { } }); - if (!iError && data && data.Result && data.Result.Reload) { + if (!iError && data.Result.Reload) { location.reload(); } else { PackageAdminStore.fetch(); diff --git a/dev/Settings/Admin/Plugins.js b/dev/Settings/Admin/Plugins.js index e5d4aef44..9c0a3f80a 100644 --- a/dev/Settings/Admin/Plugins.js +++ b/dev/Settings/Admin/Plugins.js @@ -60,13 +60,11 @@ export class PluginsAdminSettings { } onPluginDisableRequest(iError, data) { - if (!iError && data) { - if (!data.Result && data.ErrorCode) { - if (Notification.UnsupportedPluginPackage === data.ErrorCode && data.ErrorMessage && data.ErrorMessage) { - PluginAdminStore.error(data.ErrorMessage); - } else { - PluginAdminStore.error(getNotification(data.ErrorCode)); - } + if (iError) { + if (Notification.UnsupportedPluginPackage === iError && data && data.ErrorMessage) { + PluginAdminStore.error(data.ErrorMessage); + } else { + PluginAdminStore.error(getNotification(iError)); } } diff --git a/dev/Settings/User/Filters.js b/dev/Settings/User/Filters.js index b4016a44c..212302659 100644 --- a/dev/Settings/User/Filters.js +++ b/dev/Settings/User/Filters.js @@ -1,6 +1,5 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; import { getNotification } from 'Common/Translator'; import { addObservablesTo } from 'Common/Utils'; import { delegateRunOnDestroy } from 'Common/UtilsUser'; @@ -41,7 +40,10 @@ export class FiltersUserSettings { this.loading(false); this.scripts([]); - if (!iError && data && data.Result) { + if (iError) { + SieveUserStore.capa([]); + this.setError(getNotification(iError)); + } else { SieveUserStore.capa(data.Result.Capa); /* this.scripts( @@ -52,11 +54,6 @@ export class FiltersUserSettings { value = SieveScriptModel.reviveFromJson(value); value && this.scripts.push(value) }); - } else { - SieveUserStore.capa([]); - this.setError( - data && data.ErrorCode ? getNotification(data.ErrorCode) : getNotification(Notification.CantGetFilters) - ); } }); } @@ -73,15 +70,12 @@ export class FiltersUserSettings { deleteScript(script) { this.serverError(false); Remote.filtersScriptDelete( - (result, data) => { - if (Remote.SUCCESS === result && data && data.Result) { + (iError, data) => { + if (iError) { + this.setError((data && data.ErrorMessageAdditional) || getNotification(iError)); + } else { this.scripts.remove(script); delegateRunOnDestroy(script); - } else { - this.setError((data && data.ErrorCode) - ? (data.ErrorMessageAdditional || getNotification(data.ErrorCode)) - : getNotification(Notification.CantActivateFiltersScript) - ); } }, script.name() @@ -92,14 +86,11 @@ export class FiltersUserSettings { let name = script.active() ? '' : script.name(); this.serverError(false); Remote.filtersScriptActivate( - (result, data) => { - if (Remote.SUCCESS === result && data && data.Result) { - this.scripts.forEach(script => script.active(script.name() === name)); + (iError, data) => { + if (iError) { + this.setError((data && data.ErrorMessageAdditional) || iError) } else { - this.setError((data && data.ErrorCode) - ? (data.ErrorMessageAdditional || getNotification(data.ErrorCode)) - : getNotification(Notification.CantActivateFiltersScript) - ); + this.scripts.forEach(script => script.active(script.name() === name)); } }, name diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 144f71d54..3d597c676 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -640,15 +640,14 @@ export const MessageUserStore = new class { * @param {boolean} bCached */ onMessageResponse(iError, oData, bCached) { - if (!iError && oData && oData.Result) { + if (iError) { + if (Notification.RequestAborted !== iError) { + this.message(null); + this.messageError(getNotification(iError)); + } + } else { this.setMessage(oData, bCached); - } else if (Remote.ABORT !== iError) { - this.message(null); - this.messageError( - oData && oData.ErrorCode ? getNotification(oData.ErrorCode) : getNotification(Notification.UnknownError) - ); } - this.messageLoading(false); } @@ -663,7 +662,7 @@ export const MessageUserStore = new class { } setMessageList(data, cached) { - const collection = data && MessageCollectionModel.reviveFromJson(data.Result, cached); + const collection = MessageCollectionModel.reviveFromJson(data.Result, cached); if (collection) { let unreadCountChange = false; @@ -715,7 +714,7 @@ export const MessageUserStore = new class { } else { this.listCount(0); this.list([]); - this.listError(getNotification(data && data.ErrorCode ? data.ErrorCode : Notification.CantGetMessageList)); + this.listError(getNotification(Notification.CantGetMessageList)); } } }; diff --git a/dev/View/Admin/Login.js b/dev/View/Admin/Login.js index 40decf862..70cc17bb9 100644 --- a/dev/View/Admin/Login.js +++ b/dev/View/Admin/Login.js @@ -1,6 +1,5 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; import { Settings } from 'Common/Globals'; import { getNotification } from 'Common/Translator'; @@ -59,17 +58,12 @@ class LoginAdminView extends AbstractViewCenter { this.submitRequest(true); Remote.adminLogin( - (iError, oData) => { - if (!iError && oData && 'AdminLogin' === oData.Action) { - if (oData.Result) { - rl.route.reload(); - } else if (oData.ErrorCode) { - this.submitRequest(false); - this.submitError(getNotification(oData.ErrorCode)); - } + (iError) => { + this.submitRequest(false); + if (iError) { + this.submitError(getNotification(iError)); } else { - this.submitRequest(false); - this.submitError(getNotification(Notification.UnknownError)); + rl.route.reload(); } }, this.login(), diff --git a/dev/View/Popup/Account.js b/dev/View/Popup/Account.js index 3596c7cd4..bae194ee2 100644 --- a/dev/View/Popup/Account.js +++ b/dev/View/Popup/Account.js @@ -1,4 +1,3 @@ -import { Notification } from 'Common/Enums'; import { getNotification } from 'Common/Translator'; import Remote from 'Remote/User/Fetch'; @@ -48,22 +47,12 @@ class AccountPopupView extends AbstractViewPopup { Remote.accountSetup( (iError, data) => { this.submitRequest(false); - if (!iError && data) { - if (data.Result) { - rl.app.accountsAndIdentities(); - this.cancelCommand(); - } else { - this.submitError( - data.ErrorCode ? getNotification(data.ErrorCode) : getNotification(Notification.UnknownError) - ); - - if (data.ErrorMessageAdditional) { - this.submitErrorAdditional(data.ErrorMessageAdditional); - } - } + if (iError) { + this.submitError(getNotification(iError)); + this.submitErrorAdditional((data && data.ErrorMessageAdditional) || ''); } else { - this.submitError(getNotification(Notification.UnknownError)); - this.submitErrorAdditional(''); + rl.app.accountsAndIdentities(); + this.cancelCommand(); } }, this.email(), diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 0f83b78ae..2caa29f41 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -579,28 +579,21 @@ class ComposePopupView extends AbstractViewPopup { } sendMessageResponse(iError, data) { - let result = false, - message = ''; this.sending(false); - if (!iError && data && data.Result) { - result = true; - this.modalVisibility() && this.closeCommand && this.closeCommand(); - } - - if (this.modalVisibility() && !result) { - if (data && Notification.CantSaveMessage === data.ErrorCode) { - this.sendSuccessButSaveError(true); - this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim()); + if (this.modalVisibility()) { + if (iError) { + if (Notification.CantSaveMessage === iError) { + this.sendSuccessButSaveError(true); + this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim()); + } else { + this.sendError(true); + this.sendErrorDesc(getNotification(iError, data && data.ErrorMessage) + || getNotification(Notification.CantSendMessage)); + } } else { - message = getNotification( - data && data.ErrorCode ? data.ErrorCode : Notification.CantSendMessage, - data && data.ErrorMessage ? data.ErrorMessage : '' - ); - - this.sendError(true); - this.sendErrorDesc(message || getNotification(Notification.CantSendMessage)); + this.closeCommand && this.closeCommand(); } } diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 7a6e95bc7..39fb0db49 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -2,7 +2,6 @@ import ko from 'ko'; import { SaveSettingsStep, - Notification, Scope } from 'Common/Enums'; @@ -255,10 +254,8 @@ class ContactsPopupView extends AbstractViewPopup { } syncCommand() { - rl.app.contactsSync((iError, data) => { - if (iError || !data || !data.Result) { - alert(getNotification(data && data.ErrorCode ? data.ErrorCode : Notification.ContactsSyncError)); - } + rl.app.contactsSync(iError => { + iError && alert(getNotification(iError)); this.reloadContactList(true); }); diff --git a/dev/View/Popup/Domain.js b/dev/View/Popup/Domain.js index 5921b02bb..0a086c929 100644 --- a/dev/View/Popup/Domain.js +++ b/dev/View/Popup/Domain.js @@ -1,6 +1,5 @@ -import { Notification } from 'Common/Enums'; import { pInt, pString } from 'Common/Utils'; -import { i18n } from 'Common/Translator'; +import { i18n, getNotification } from 'Common/Translator'; import Remote from 'Remote/Admin/Fetch'; @@ -248,17 +247,13 @@ class DomainPopupView extends AbstractViewPopup { } } - onDomainCreateOrSaveResponse(iError, oData) { + onDomainCreateOrSaveResponse(iError) { this.saving(false); - if (!iError && oData) { - if (oData.Result) { - DomainAdminStore.fetch(); - this.closeCommand(); - } else if (Notification.DomainAlreadyExists === oData.ErrorCode) { - this.savingError(i18n('ERRORS/DOMAIN_ALREADY_EXISTS')); - } + if (iError) { + this.savingError(getNotification(iError)); } else { - this.savingError(i18n('ERRORS/UNKNOWN_ERROR')); + DomainAdminStore.fetch(); + this.closeCommand(); } } diff --git a/dev/View/Popup/DomainAlias.js b/dev/View/Popup/DomainAlias.js index d36c6e2d6..cecd86acb 100644 --- a/dev/View/Popup/DomainAlias.js +++ b/dev/View/Popup/DomainAlias.js @@ -1,7 +1,6 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; -import { i18n } from 'Common/Translator'; +import { getNotification } from 'Common/Translator'; import { DomainAdminStore } from 'Stores/Admin/Domain'; @@ -29,8 +28,6 @@ class DomainAliasPopupView extends AbstractViewPopup { this.canBeSaved = ko.computed(() => !this.saving() && this.name() && this.alias()); - this.onDomainAliasCreateOrSaveResponse = this.onDomainAliasCreateOrSaveResponse.bind(this); - decorateKoCommands(this, { createCommand: self => self.canBeSaved() }); @@ -38,21 +35,15 @@ class DomainAliasPopupView extends AbstractViewPopup { createCommand() { this.saving(true); - Remote.createDomainAlias(this.onDomainAliasCreateOrSaveResponse, this.name(), this.alias()); - } - - onDomainAliasCreateOrSaveResponse(iError, data) { - this.saving(false); - if (!iError && data) { - if (data.Result) { + Remote.createDomainAlias(iError => { + this.saving(false); + if (iError) { + this.savingError(getNotification(iError)); + } else { DomainAdminStore.fetch(); this.closeCommand(); - } else if (Notification.DomainAlreadyExists === data.ErrorCode) { - this.savingError(i18n('ERRORS/DOMAIN_ALREADY_EXISTS')); } - } else { - this.savingError(i18n('ERRORS/UNKNOWN_ERROR')); - } + }, this.name(), this.alias()); } onShow() { diff --git a/dev/View/Popup/FolderClear.js b/dev/View/Popup/FolderClear.js index 58ab0cc9d..bcfe7dc7f 100644 --- a/dev/View/Popup/FolderClear.js +++ b/dev/View/Popup/FolderClear.js @@ -1,4 +1,3 @@ -import { Notification } from 'Common/Enums'; import { i18n, getNotification } from 'Common/Translator'; import { setFolderHash } from 'Common/Cache'; @@ -54,17 +53,13 @@ class FolderClearPopupView extends AbstractViewPopup { setFolderHash(folderToClear.fullNameRaw, ''); - Remote.folderClear((iError, data) => { + Remote.folderClear(iError => { this.clearingProcess(false); - if (!iError && data && data.Result) { + if (iError) { + this.clearingError(getNotification(iError)); + } else { rl.app.reloadMessageList(true); this.cancelCommand(); - } else { - if (data && data.ErrorCode) { - this.clearingError(getNotification(data.ErrorCode)); - } else { - this.clearingError(getNotification(Notification.MailServerError)); - } } }, folderToClear.fullNameRaw); } diff --git a/dev/View/Popup/Identity.js b/dev/View/Popup/Identity.js index 68e740fad..65f18e5a6 100644 --- a/dev/View/Popup/Identity.js +++ b/dev/View/Popup/Identity.js @@ -1,4 +1,3 @@ -import { Notification } from 'Common/Enums'; import { getNotification } from 'Common/Translator'; import Remote from 'Remote/User/Fetch'; @@ -96,17 +95,13 @@ class IdentityPopupView extends AbstractViewPopup { this.submitRequest(true); Remote.identityUpdate( - (iError, data) => { + iError => { this.submitRequest(false); - if (!iError && data) { - if (data.Result) { - rl.app.accountsAndIdentities(); - this.cancelCommand(); - } else if (data.ErrorCode) { - this.submitError(getNotification(data.ErrorCode)); - } + if (iError) { + this.submitError(getNotification(iError)); } else { - this.submitError(getNotification(Notification.UnknownError)); + rl.app.accountsAndIdentities(); + this.cancelCommand(); } }, this.id, diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index 283b1a102..adae75ffa 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -1,6 +1,6 @@ import ko from 'ko'; -import { Scope, Notification } from 'Common/Enums'; +import { Scope } from 'Common/Enums'; import { getNotification, i18n } from 'Common/Translator'; import { isNonEmptyArray } from 'Common/Utils'; @@ -53,16 +53,11 @@ class PluginPopupView extends AbstractViewPopup { Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list); } - onPluginSettingsUpdateResponse(iError, data) { - if (!iError && data && data.Result) { - this.cancelCommand(); + onPluginSettingsUpdateResponse(iError) { + if (iError) { + this.saveError(getNotification(iError)); } else { - this.saveError(''); - if (data && data.ErrorCode) { - this.saveError(getNotification(data.ErrorCode)); - } else { - this.saveError(getNotification(Notification.CantSavePluginSettings)); - } + this.cancelCommand(); } } diff --git a/dev/View/Popup/SieveScript.js b/dev/View/Popup/SieveScript.js index c3c849274..ab15918e5 100644 --- a/dev/View/Popup/SieveScript.js +++ b/dev/View/Popup/SieveScript.js @@ -1,6 +1,5 @@ import ko from 'ko'; -import { Notification } from 'Common/Enums'; import { getNotification, i18nToNodes } from 'Common/Translator'; import { addObservablesTo } from 'Common/Utils'; import { delegateRunOnDestroy } from 'Common/UtilsUser'; @@ -61,16 +60,13 @@ class SieveScriptPopupView extends AbstractViewPopup { (iError, data) => { self.saving = false; - if (!iError && data && data.Result) { + if (iError) { + self.saveError(true); + self.saveErrorText((data && data.ErrorMessageAdditional) || getNotification(iError)); + } else { script.exists() || SieveUserStore.scripts.push(script); script.exists(true); script.hasChanges(false); - } else { - self.saveError(true); - self.saveErrorText((data && data.ErrorCode) - ? (data.ErrorMessageAdditional || getNotification(data.ErrorCode)) - : getNotification(Notification.CantSaveFilters) - ); } }, script diff --git a/dev/View/Popup/Template.js b/dev/View/Popup/Template.js index c8581f4f6..08fc82552 100644 --- a/dev/View/Popup/Template.js +++ b/dev/View/Popup/Template.js @@ -1,4 +1,3 @@ -import { Notification } from 'Common/Enums'; import { getNotification } from 'Common/Translator'; import { HtmlEditor } from 'Common/Html'; @@ -53,17 +52,13 @@ class TemplatePopupView extends AbstractViewPopup { this.submitRequest(true); Remote.templateSetup( - (iError, data) => { + iError => { this.submitRequest(false); - if (!iError && data) { - if (data.Result) { - rl.app.templates(); - this.cancelCommand(); - } else if (data.ErrorCode) { - this.submitError(getNotification(data.ErrorCode)); - } + if (iError) { + this.submitError(getNotification(iError)); } else { - this.submitError(getNotification(Notification.UnknownError)); + rl.app.templates(); + this.cancelCommand(); } }, this.id(), diff --git a/dev/View/User/Login.js b/dev/View/User/Login.js index 33f82371d..f9a3d4593 100644 --- a/dev/View/User/Login.js +++ b/dev/View/User/Login.js @@ -6,7 +6,7 @@ import { import { ClientSideKeyName } from 'Common/EnumsUser'; -import { getNotification, getNotificationFromResponse, reload as translatorReload, convertLangName } from 'Common/Translator'; +import { getNotification, reload as translatorReload, convertLangName } from 'Common/Translator'; import { LanguageStore } from 'Stores/Language'; @@ -150,36 +150,21 @@ class LoginUserView extends AbstractViewCenter { const fLoginRequest = (sLoginPassword) => { Remote.login( (iError, oData) => { - if (!iError && oData && 'Login' === oData.Action) { - if (oData.Result) { - if (oData.TwoFactorAuth) { - this.additionalCode(''); - this.additionalCodeVisibility(true); - this.submitRequest(false); - - setTimeout(() => this.querySelector('.inputAdditionalCode').focus(), 100); - } else { - rl.route.reload(); - } - } else if (oData.ErrorCode) { - this.submitRequest(false); - if ([Notification.InvalidInputArgument].includes(oData.ErrorCode)) { - oData.ErrorCode = Notification.AuthError; - } - - this.submitError(getNotificationFromResponse(oData)); - - if (!this.submitError()) { - this.submitError(getNotification(Notification.UnknownError)); - } else if (oData.ErrorMessageAdditional) { - this.submitErrorAddidional(oData.ErrorMessageAdditional); - } - } else { - this.submitRequest(false); + this.submitRequest(false); + if (iError) { + if (Notification.InvalidInputArgument == iError) { + iError = Notification.AuthError; } + this.submitError(getNotification(iError, oData.ErrorMessage, Notification.UnknownNotification)); + this.submitErrorAddidional((oData && oData.ErrorMessageAdditional) || ''); } else { - this.submitRequest(false); - this.submitError(getNotification(Notification.UnknownError)); + if (oData.TwoFactorAuth) { + this.additionalCode(''); + this.additionalCodeVisibility(true); + setTimeout(() => this.querySelector('.inputAdditionalCode').focus(), 100); + } else { + rl.route.reload(); + } } }, this.email(), diff --git a/dev/bootstrap.js b/dev/bootstrap.js index 28cc47620..f93cc88b2 100644 --- a/dev/bootstrap.js +++ b/dev/bootstrap.js @@ -37,8 +37,7 @@ export default (App) => { StorageResultType: { Success: 0, Error: 1, - Abort: 2, - Unload: 3 + Abort: 2 } }; diff --git a/plugins/change-password/js/ChangePasswordUserSettings.js b/plugins/change-password/js/ChangePasswordUserSettings.js index 9f416d91f..8592b6b9e 100644 --- a/plugins/change-password/js/ChangePasswordUserSettings.js +++ b/plugins/change-password/js/ChangePasswordUserSettings.js @@ -108,25 +108,21 @@ onChangePasswordResponse(iError, data) { this.reset(false); - if (!iError && data && data.Result) { + if (iError) { + this.passwordUpdateError(true); + if (131 === iError) { + // Notification.CurrentPasswordIncorrect + this.currentPasswordError(true); + } + this.errorDescription((data && data.ErrorMessageAdditional) + || rl.i18n('NOTIFICATIONS/COULD_NOT_SAVE_NEW_PASSWORD')); + } else { this.currentPassword(''); this.newPassword(''); this.newPassword2(''); this.passwordUpdateSuccess(true); rl.hash.set(); rl.settings.set('AuthAccountHash', data.Result); - } else { - this.passwordUpdateError(true); - this.errorDescription(rl.i18n('NOTIFICATIONS/COULD_NOT_SAVE_NEW_PASSWORD')); - if (data) { - if (131 === data.ErrorCode) { - // Notification.CurrentPasswordIncorrect - this.currentPasswordError(true); - } - if (data.ErrorMessageAdditional) { - this.errorDescription(data.ErrorMessageAdditional); - } - } } } } diff --git a/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js b/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js index 94ee0897f..20bd0d6f5 100644 --- a/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js +++ b/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js @@ -22,11 +22,11 @@ this.loading(true); - rl.pluginRemoteRequest(function (iError, oData) { + rl.pluginRemoteRequest((iError, oData) => { self.loading(false); - if (!iError && oData && oData.Result) { + if (!iError) { self.php(oData.Result.PHP || ''); } diff --git a/plugins/custom-settings-tab/js/CustomUserSettings.js b/plugins/custom-settings-tab/js/CustomUserSettings.js index 127082a18..85b7f5241 100644 --- a/plugins/custom-settings-tab/js/CustomUserSettings.js +++ b/plugins/custom-settings-tab/js/CustomUserSettings.js @@ -33,11 +33,11 @@ this.saving(true); - rl.pluginRemoteRequest(function (iError, oData) { + rl.pluginRemoteRequest((iError, oData) => { self.saving(false); - if (!iError && oData && oData.Result) + if (!iError) { // true } @@ -61,11 +61,11 @@ this.loading(true); - rl.pluginRemoteRequest(function (iError, oData) { + rl.pluginRemoteRequest((iError, oData) => { self.loading(false); - if (!iError && oData && oData.Result) + if (!iError) { self.userSkype(oData.Result.UserSkype || ''); self.userFacebook(oData.Result.UserFacebook || '');