mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-28 09:41:29 +08:00
Improved Fetch error handling
This commit is contained in:
parent
1a82dde49b
commit
3426921c9d
4 changed files with 12 additions and 16 deletions
|
@ -67,14 +67,7 @@ fetchJSON = (action, sGetAdd, params, timeout, jsonCallback) => {
|
||||||
oRequests[action] = controller;
|
oRequests[action] = controller;
|
||||||
init.signal = controller.signal;
|
init.signal = controller.signal;
|
||||||
}
|
}
|
||||||
return rl.fetchJSON(getURL(sGetAdd), init, sGetAdd ? null : params)
|
return rl.fetchJSON(getURL(sGetAdd), init, sGetAdd ? null : params).then(jsonCallback);
|
||||||
.then(jsonCallback)
|
|
||||||
.catch(err => {
|
|
||||||
if (err.name == 'AbortError') { // handle abort()
|
|
||||||
err = Notification.JsonAbort;
|
|
||||||
}
|
|
||||||
return Promise.reject(err);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addEventListener('unload', () => bUnload = true);
|
addEventListener('unload', () => bUnload = true);
|
||||||
|
@ -103,7 +96,7 @@ export class AbstractFetchRemote
|
||||||
abortActions.forEach(actionToAbort => abort(actionToAbort));
|
abortActions.forEach(actionToAbort => abort(actionToAbort));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetchJSON(sAction, sGetAdd,
|
fetchJSON(sAction, sGetAdd,
|
||||||
params,
|
params,
|
||||||
undefined === iTimeout ? 30000 : pInt(iTimeout),
|
undefined === iTimeout ? 30000 : pInt(iTimeout),
|
||||||
data => {
|
data => {
|
||||||
|
@ -163,7 +156,11 @@ export class AbstractFetchRemote
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
fCallback && fCallback(err.name == 'AbortError' ? Notification.JsonAbort : StorageResultType.Error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -128,7 +128,7 @@ class RemoteAdminFetch extends AbstractFetchRemote {
|
||||||
* @param {boolean} bDisabled
|
* @param {boolean} bDisabled
|
||||||
*/
|
*/
|
||||||
domainDisable(fCallback, sName, bDisabled) {
|
domainDisable(fCallback, sName, bDisabled) {
|
||||||
return this.defaultRequest(fCallback, 'AdminDomainDisable', {
|
this.defaultRequest(fCallback, 'AdminDomainDisable', {
|
||||||
Name: sName,
|
Name: sName,
|
||||||
Disabled: bDisabled ? 1 : 0
|
Disabled: bDisabled ? 1 : 0
|
||||||
});
|
});
|
||||||
|
@ -139,7 +139,7 @@ class RemoteAdminFetch extends AbstractFetchRemote {
|
||||||
* @param {Object} oConfig
|
* @param {Object} oConfig
|
||||||
*/
|
*/
|
||||||
pluginSettingsUpdate(fCallback, oConfig) {
|
pluginSettingsUpdate(fCallback, oConfig) {
|
||||||
return this.defaultRequest(fCallback, 'AdminPluginSettingsUpdate', oConfig);
|
this.defaultRequest(fCallback, 'AdminPluginSettingsUpdate', oConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,7 +148,7 @@ class RemoteAdminFetch extends AbstractFetchRemote {
|
||||||
* @param {boolean} bDisabled
|
* @param {boolean} bDisabled
|
||||||
*/
|
*/
|
||||||
pluginDisable(fCallback, sName, bDisabled) {
|
pluginDisable(fCallback, sName, bDisabled) {
|
||||||
return this.defaultRequest(fCallback, 'AdminPluginDisable', {
|
this.defaultRequest(fCallback, 'AdminPluginDisable', {
|
||||||
Name: sName,
|
Name: sName,
|
||||||
Disabled: bDisabled ? 1 : 0
|
Disabled: bDisabled ? 1 : 0
|
||||||
});
|
});
|
||||||
|
|
|
@ -340,7 +340,7 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.defaultRequest(
|
this.defaultRequest(
|
||||||
fCallback,
|
fCallback,
|
||||||
'MessageList',
|
'MessageList',
|
||||||
params,
|
params,
|
||||||
|
|
3
dev/bootstrap.js
vendored
3
dev/bootstrap.js
vendored
|
@ -109,8 +109,7 @@ export default (App) => {
|
||||||
|
|
||||||
return fetch(resource, init).then(response => {
|
return fetch(resource, init).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
// return Promise.reject('Network response error: ' + response.status);
|
return Promise.reject('Network response error: ' + response.status);
|
||||||
throw new Error('Network response error: ' + response.status);
|
|
||||||
}
|
}
|
||||||
/* TODO: use this for non-developers?
|
/* TODO: use this for non-developers?
|
||||||
response.clone()
|
response.clone()
|
||||||
|
|
Loading…
Reference in a new issue