Notify: auto-retry once after 10 seconds

Also:
- Show the resume button on notify errors.
- Changed the error message to differentiate against v1's.
This commit is contained in:
infinite-persistence 2021-11-11 09:55:48 +08:00
parent b5f1ae1291
commit 7ef5975ee8
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -56,7 +56,9 @@ export function makeResumableUploadRequest(
window.store.dispatch(doUpdateUploadProgress({ params, progress: percentage })); window.store.dispatch(doUpdateUploadProgress({ params, progress: percentage }));
}, },
onSuccess: () => { onSuccess: () => {
// Notify lbrynet server let retries = 2;
function makeNotifyRequest() {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('POST', `${uploader.url}/notify`); xhr.open('POST', `${uploader.url}/notify`);
xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Content-Type', 'application/json');
@ -68,13 +70,22 @@ export function makeResumableUploadRequest(
resolve(xhr); resolve(xhr);
}; };
xhr.onerror = () => { xhr.onerror = () => {
reject(new Error(__('There was a problem with your upload. Please try again.'))); if (--retries > 0) {
// Auto-retry after 10s delay.
setTimeout(() => makeNotifyRequest(), 10000);
} else {
window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));
reject(new Error(__('There was a problem in the processing. Please retry.')));
}
}; };
xhr.onabort = () => { xhr.onabort = () => {
window.store.dispatch(doUpdateUploadRemove(params)); window.store.dispatch(doUpdateUploadRemove(params));
}; };
xhr.send(jsonPayload); xhr.send(jsonPayload);
}
makeNotifyRequest();
}, },
}); });