mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-27 09:08:26 +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;
|
||||
init.signal = controller.signal;
|
||||
}
|
||||
return rl.fetchJSON(getURL(sGetAdd), init, sGetAdd ? null : params)
|
||||
.then(jsonCallback)
|
||||
.catch(err => {
|
||||
if (err.name == 'AbortError') { // handle abort()
|
||||
err = Notification.JsonAbort;
|
||||
}
|
||||
return Promise.reject(err);
|
||||
});
|
||||
return rl.fetchJSON(getURL(sGetAdd), init, sGetAdd ? null : params).then(jsonCallback);
|
||||
};
|
||||
|
||||
addEventListener('unload', () => bUnload = true);
|
||||
|
@ -103,7 +96,7 @@ export class AbstractFetchRemote
|
|||
abortActions.forEach(actionToAbort => abort(actionToAbort));
|
||||
}
|
||||
|
||||
return fetchJSON(sAction, sGetAdd,
|
||||
fetchJSON(sAction, sGetAdd,
|
||||
params,
|
||||
undefined === iTimeout ? 30000 : pInt(iTimeout),
|
||||
data => {
|
||||
|
@ -163,7 +156,11 @@ export class AbstractFetchRemote
|
|||
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
|
||||
*/
|
||||
domainDisable(fCallback, sName, bDisabled) {
|
||||
return this.defaultRequest(fCallback, 'AdminDomainDisable', {
|
||||
this.defaultRequest(fCallback, 'AdminDomainDisable', {
|
||||
Name: sName,
|
||||
Disabled: bDisabled ? 1 : 0
|
||||
});
|
||||
|
@ -139,7 +139,7 @@ class RemoteAdminFetch extends AbstractFetchRemote {
|
|||
* @param {Object} 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
|
||||
*/
|
||||
pluginDisable(fCallback, sName, bDisabled) {
|
||||
return this.defaultRequest(fCallback, 'AdminPluginDisable', {
|
||||
this.defaultRequest(fCallback, 'AdminPluginDisable', {
|
||||
Name: sName,
|
||||
Disabled: bDisabled ? 1 : 0
|
||||
});
|
||||
|
|
|
@ -340,7 +340,7 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
};
|
||||
}
|
||||
|
||||
return this.defaultRequest(
|
||||
this.defaultRequest(
|
||||
fCallback,
|
||||
'MessageList',
|
||||
params,
|
||||
|
|
3
dev/bootstrap.js
vendored
3
dev/bootstrap.js
vendored
|
@ -109,8 +109,7 @@ export default (App) => {
|
|||
|
||||
return fetch(resource, init).then(response => {
|
||||
if (!response.ok) {
|
||||
// return Promise.reject('Network response error: ' + response.status);
|
||||
throw new Error('Network response error: ' + response.status);
|
||||
return Promise.reject('Network response error: ' + response.status);
|
||||
}
|
||||
/* TODO: use this for non-developers?
|
||||
response.clone()
|
||||
|
|
Loading…
Reference in a new issue