From 62e7fe06a56193a9a8c0df8e1e102c696c1bcc2f Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Fri, 12 Nov 2021 14:12:51 +0800 Subject: [PATCH] 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. --- web/setup/publish-v2.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/setup/publish-v2.js b/web/setup/publish-v2.js index 9d6bcbda1..832361148 100644 --- a/web/setup/publish-v2.js +++ b/web/setup/publish-v2.js @@ -8,6 +8,20 @@ const RESUMABLE_ENDPOINT = LBRY_WEB_PUBLISH_API_V2; const RESUMABLE_ENDPOINT_METHOD = 'publish'; 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( token: string, params: FileUploadSdkParams, @@ -46,9 +60,8 @@ export function makeResumableUploadRequest( }, onShouldRetry: (err, retryAttempt, options) => { window.store.dispatch(doUpdateUploadProgress({ params, status: 'retry' })); - const FORBIDDEN_ERROR = 403; const status = err.originalResponse ? err.originalResponse.getStatus() : 0; - return status !== FORBIDDEN_ERROR; + return !inStatusCategory(status, 400) || status === STATUS_CONFLICT || status === STATUS_LOCKED; }, onError: (error) => { window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));