Set response ErrorCode as iError for easier fetch error handling

This commit is contained in:
djmaze 2021-03-18 12:33:13 +01:00
parent a46c0c3b21
commit 11fd6736bb
24 changed files with 145 additions and 253 deletions

View file

@ -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(),

View file

@ -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(),

View file

@ -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();
}
}

View file

@ -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);
});

View file

@ -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();
}
}

View file

@ -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() {

View file

@ -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);
}

View file

@ -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,

View file

@ -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();
}
}

View file

@ -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

View file

@ -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(),

View file

@ -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(),