Notify: Re-enable delay but only for initial connection problem

We want to avoid the double `notify`, and also to confirm whether the SDK is timing out.
This commit is contained in:
infinite-persistence 2021-11-12 11:09:25 +08:00 committed by infinite-persistence
parent 9bfa1a3577
commit 861aaf4cde

View file

@ -56,7 +56,7 @@ export function makeResumableUploadRequest(
window.store.dispatch(doUpdateUploadProgress({ params, progress: percentage }));
},
onSuccess: () => {
let retries = 0;
let retries = 1;
function makeNotifyRequest() {
const xhr = new XMLHttpRequest();
@ -70,9 +70,9 @@ export function makeResumableUploadRequest(
resolve(xhr);
};
xhr.onerror = () => {
if (--retries > 0) {
// Auto-retry after 10s delay.
setTimeout(() => makeNotifyRequest(), 10000);
if (retries > 0 && xhr.status === 0) {
--retries;
setTimeout(() => makeNotifyRequest(), 10000); // Auto-retry after 10s delay.
} else {
window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));
reject(new Error(`There was a problem in the processing. Please retry. (${xhr.status})`));