tus: delay adjustments + clean up error messages #687
This commit is contained in:
commit
3c3d73a189
1 changed files with 19 additions and 24 deletions
|
@ -60,7 +60,7 @@ export function makeResumableUploadRequest(
|
||||||
const uploader = new tus.Upload(file, {
|
const uploader = new tus.Upload(file, {
|
||||||
...urlOptions,
|
...urlOptions,
|
||||||
chunkSize: UPLOAD_CHUNK_SIZE_BYTE,
|
chunkSize: UPLOAD_CHUNK_SIZE_BYTE,
|
||||||
retryDelays: [0, 5000, 10000, 15000, 30000],
|
retryDelays: [5000, 10000, 30000],
|
||||||
parallelUploads: 1,
|
parallelUploads: 1,
|
||||||
storeFingerprintForResuming: false,
|
storeFingerprintForResuming: false,
|
||||||
removeFingerprintOnSuccess: true,
|
removeFingerprintOnSuccess: true,
|
||||||
|
@ -72,36 +72,31 @@ export function makeResumableUploadRequest(
|
||||||
onShouldRetry: (err, retryAttempt, options) => {
|
onShouldRetry: (err, retryAttempt, options) => {
|
||||||
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'retry' }));
|
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'retry' }));
|
||||||
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
||||||
analytics.error(`tus: retry=${uploader._retryAttempt}, status=${status}`);
|
|
||||||
return !inStatusCategory(status, 400) || status === STATUS_CONFLICT || status === STATUS_LOCKED;
|
return !inStatusCategory(status, 400) || status === STATUS_CONFLICT || status === STATUS_LOCKED;
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
||||||
const errMsg = typeof err === 'string' ? err : err.message;
|
const errMsg = typeof err === 'string' ? err : err.message;
|
||||||
|
|
||||||
if (status === STATUS_CONFLICT) {
|
let customErr;
|
||||||
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'conflict' }));
|
if (status === STATUS_LOCKED || errMsg === 'file currently locked') {
|
||||||
reject(new Error(`${status}: concurrent upload detected.`));
|
customErr = 'File is locked. Try resuming after waiting a few minutes';
|
||||||
} else {
|
|
||||||
const errToLog =
|
|
||||||
status === STATUS_LOCKED || errMsg === 'file currently locked'
|
|
||||||
? 'File is locked. Try resuming after waiting a few minutes'
|
|
||||||
: err;
|
|
||||||
|
|
||||||
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'error' }));
|
|
||||||
reject(
|
|
||||||
// $FlowFixMe - flow's constructor for Error is incorrect.
|
|
||||||
new Error(errToLog, {
|
|
||||||
cause: {
|
|
||||||
url: uploader.url,
|
|
||||||
status,
|
|
||||||
...(uploader._fingerprint ? { fingerprint: uploader._fingerprint } : {}),
|
|
||||||
...(uploader._retryAttempt ? { retryAttempt: uploader._retryAttempt } : {}),
|
|
||||||
...(uploader._offsetBeforeRetry ? { offsetBeforeRetry: uploader._offsetBeforeRetry } : {}),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'error' }));
|
||||||
|
reject(
|
||||||
|
// $FlowFixMe - flow's constructor for Error is incorrect.
|
||||||
|
new Error(customErr || err, {
|
||||||
|
cause: {
|
||||||
|
url: uploader.url,
|
||||||
|
status,
|
||||||
|
...(uploader._fingerprint ? { fingerprint: uploader._fingerprint } : {}),
|
||||||
|
...(uploader._retryAttempt ? { retryAttempt: uploader._retryAttempt } : {}),
|
||||||
|
...(uploader._offsetBeforeRetry ? { offsetBeforeRetry: uploader._offsetBeforeRetry } : {}),
|
||||||
|
...(customErr ? { original: errMsg } : {}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
},
|
},
|
||||||
onProgress: (bytesUploaded, bytesTotal) => {
|
onProgress: (bytesUploaded, bytesTotal) => {
|
||||||
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
|
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
|
||||||
|
|
Loading…
Reference in a new issue