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:
infinite-persistence 2021-11-12 14:12:51 +08:00
parent dfe30b6d78
commit 62e7fe06a5
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -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' }));