From 89feddee0dc8acc5ce732dc8ab8a629727b0d61d Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Mon, 4 Apr 2022 13:51:45 +0800 Subject: [PATCH] Publish: handle failed 'notify' at the server Ticket: 1256 For `notify`, "file is currently locked" and "no such file or directory" is indication that the previous "failed" SDK call actually worked. Tell the user to check the transactions. This is the band aid until odysee-api/401 is addressed. --- .prettierignore | 1 + static/app-strings.json | 1 + ui/constants/errors.js | 1 + ui/redux/actions/publish.js | 11 +++++++++-- web/setup/publish.js | 8 ++++++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.prettierignore b/.prettierignore index df9b7ce6d..52da1ff1f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ **/plugins/inline-attachment/** +**/ui/constants/errors.js diff --git a/static/app-strings.json b/static/app-strings.json index ccda83135..a1738fbf8 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -2230,5 +2230,6 @@ "Active channel": "Active channel", "This account has livestreaming disabled, please reach out to hello@odysee.com for assistance.": "This account has livestreaming disabled, please reach out to hello@odysee.com for assistance.", "Attach images by pasting or drag-and-drop.": "Attach images by pasting or drag-and-drop.", + "There was a network error, but the publish may have been completed. Wait a few minutes, then check your Uploads or Wallet page to confirm.": "There was a network error, but the publish may have been completed. Wait a few minutes, then check your Uploads or Wallet page to confirm.", "--end--": "--end--" } diff --git a/ui/constants/errors.js b/ui/constants/errors.js index c688c8587..e1dafdef0 100644 --- a/ui/constants/errors.js +++ b/ui/constants/errors.js @@ -1,2 +1,3 @@ export const ALREADY_CLAIMED = 'once the invite reward has been claimed the referrer cannot be changed'; export const REFERRER_NOT_FOUND = 'A odysee account could not be found for the referrer you provided.'; +export const PUBLISH_TIMEOUT_BUT_LIKELY_SUCCESSFUL = 'There was a network error, but the publish may have been completed. Wait a few minutes, then check your Uploads or Wallet page to confirm.'; diff --git a/ui/redux/actions/publish.js b/ui/redux/actions/publish.js index 57b7ab6ad..834898033 100644 --- a/ui/redux/actions/publish.js +++ b/ui/redux/actions/publish.js @@ -1,4 +1,5 @@ // @flow +import { PUBLISH_TIMEOUT_BUT_LIKELY_SUCCESSFUL } from 'constants/errors'; import * as MODALS from 'constants/modal_types'; import * as ACTIONS from 'constants/action_types'; import * as PAGES from 'constants/pages'; @@ -14,7 +15,7 @@ import { selectReflectingById, } from 'redux/selectors/claims'; import { makeSelectPublishFormValue, selectPublishFormValues, selectMyClaimForUri } from 'redux/selectors/publish'; -import { doError } from 'redux/actions/notifications'; +import { doError, doToast } from 'redux/actions/notifications'; import { push } from 'connected-react-router'; import analytics from 'analytics'; import { doOpenModal, doSetIncognito, doSetActiveChannel } from 'redux/actions/app'; @@ -282,7 +283,13 @@ export const doPublishDesktop = (filePath: string, preview?: boolean) => (dispat actions.push({ type: ACTIONS.PUBLISH_FAIL, }); - actions.push(doError({ message: error.message, cause: error.cause })); + + if (error.message === PUBLISH_TIMEOUT_BUT_LIKELY_SUCCESSFUL) { + actions.push(doToast({ message: error.message, duration: 'long' })); + } else { + actions.push(doError({ message: error.message, cause: error.cause })); + } + dispatch(batchActions(...actions)); }; diff --git a/web/setup/publish.js b/web/setup/publish.js index 7d2ba1cd9..0465c1374 100644 --- a/web/setup/publish.js +++ b/web/setup/publish.js @@ -3,6 +3,7 @@ import * as tus from 'tus-js-client'; import { v4 as uuid } from 'uuid'; import { makeUploadRequest } from './publish-v1'; import { makeResumableUploadRequest } from './publish-v2'; +import { PUBLISH_TIMEOUT_BUT_LIKELY_SUCCESSFUL } from 'constants/errors'; // A modified version of Lbry.apiCall that allows // to perform calling methods at arbitrary urls @@ -54,6 +55,13 @@ export default function apiPublishCallViaWeb( if (xhr.status >= 200 && xhr.status < 300 && !xhr.response.error) { return resolve(xhr.response.result); } else if (xhr.response.error) { + if (xhr.responseURL.endsWith('/notify')) { + // Temp handling until odysee-api/issues/401 is addressed. + const errMsg = xhr.response.error.message; + if (errMsg === 'file currently locked' || errMsg.endsWith('no such file or directory')) { + return Promise.reject(new Error(PUBLISH_TIMEOUT_BUT_LIKELY_SUCCESSFUL)); + } + } error = new Error(xhr.response.error.message); } else { error = new Error(__('Upload likely timed out. Try a smaller file while we work on this.'));