TUS: Don't retry on 4xx
## Issue/Steps From Randy: - started the upload then open a new tab of the same page - one of the tab finished the upload and successfully published the file, and the other tab received 404 error on patch and head request, because the file is already removed on the server ## Changes Use the default onRetry code that ignores all 4xx, except for LOCKED and CONFLICT. Had to duplicate some code from tus because I still need to inject the 'retry' progress for the GUI to update the string.
This commit is contained in:
parent
dfe30b6d78
commit
62e7fe06a5
1 changed files with 15 additions and 2 deletions
|
@ -8,6 +8,20 @@ const RESUMABLE_ENDPOINT = LBRY_WEB_PUBLISH_API_V2;
|
||||||
const RESUMABLE_ENDPOINT_METHOD = 'publish';
|
const RESUMABLE_ENDPOINT_METHOD = 'publish';
|
||||||
const UPLOAD_CHUNK_SIZE_BYTE = 100000000;
|
const UPLOAD_CHUNK_SIZE_BYTE = 100000000;
|
||||||
|
|
||||||
|
const STATUS_CONFLICT = 409;
|
||||||
|
const STATUS_LOCKED = 423;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given status is in the range of the expected category.
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @param category
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function inStatusCategory(status, category) {
|
||||||
|
return status >= category && status < category + 100;
|
||||||
|
}
|
||||||
|
|
||||||
export function makeResumableUploadRequest(
|
export function makeResumableUploadRequest(
|
||||||
token: string,
|
token: string,
|
||||||
params: FileUploadSdkParams,
|
params: FileUploadSdkParams,
|
||||||
|
@ -46,9 +60,8 @@ export function makeResumableUploadRequest(
|
||||||
},
|
},
|
||||||
onShouldRetry: (err, retryAttempt, options) => {
|
onShouldRetry: (err, retryAttempt, options) => {
|
||||||
window.store.dispatch(doUpdateUploadProgress({ params, status: 'retry' }));
|
window.store.dispatch(doUpdateUploadProgress({ params, status: 'retry' }));
|
||||||
const FORBIDDEN_ERROR = 403;
|
|
||||||
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
|
||||||
return status !== FORBIDDEN_ERROR;
|
return !inStatusCategory(status, 400) || status === STATUS_CONFLICT || status === STATUS_LOCKED;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));
|
window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));
|
||||||
|
|
Loading…
Reference in a new issue