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

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

View file

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

View file

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