From 2f3a6fb6fbbbf837b71903922980bea258ae268f Mon Sep 17 00:00:00 2001 From: Michael An <2331806369@qq.com> Date: Thu, 12 Jun 2025 17:10:56 +0800 Subject: [PATCH] fix axios cancel error not show (#7924) * fix axios cancel error not show * fix warnings --- frontend/src/components/search/search.js | 25 ++++++++++++------------ frontend/src/utils/utils.js | 5 ----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/search/search.js b/frontend/src/components/search/search.js index a46e473454..3a67f96ca9 100644 --- a/frontend/src/components/search/search.js +++ b/frontend/src/components/search/search.js @@ -1,4 +1,5 @@ import React, { Component, Fragment } from 'react'; +import axios from 'axios'; import PropTypes from 'prop-types'; import isHotkey from 'is-hotkey'; import classnames from 'classnames'; @@ -8,7 +9,7 @@ import searchAPI from '../../utils/search-api'; import { gettext } from '../../utils/constants'; import SearchResultItem from './search-result-item'; import SearchResultLibrary from './search-result-library'; -import { debounce, Utils, isCanceled } from '../../utils/utils'; +import { debounce, Utils } from '../../utils/utils'; import toaster from '../toast'; import Loading from '../loading'; import { SEARCH_MASK, SEARCH_CONTAINER } from '../../constants/zIndexes'; @@ -398,6 +399,14 @@ class Search extends Component { }, 1); }; + handleError = (e) => { + if (!axios.isCancel(e)) { + let errMessage = Utils.getErrorMsg(e); + toaster.danger(errMessage); + } + this.setState({ isLoading: false }); + }; + getRepoSearchResult = (query_str) => { if (this.source) { this.source.cancel('prev request is cancelled'); @@ -414,11 +423,7 @@ class Search extends Component { isLoading: false, }); }).catch(error => { - if (!isCanceled(error)) { - let errMessage = Utils.getErrorMsg(error); - toaster.danger(errMessage); - } - this.setState({ isLoading: false }); + this.handleError(error); }); }; @@ -459,9 +464,7 @@ class Search extends Component { }); } }).catch(error => { - let errMessage = Utils.getErrorMsg(error); - toaster.danger(errMessage); - this.setState({ isLoading: false }); + this.handleError(error); }); } else { this.onNormalSearch(queryData, cancelToken, page); @@ -489,9 +492,7 @@ class Search extends Component { isResultGotten: true, }); }).catch(error => { - let errMessage = Utils.getErrorMsg(error); - toaster.danger(errMessage); - this.setState({ isLoading: false }); + this.handleError(error); }); }; diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index b101bdbfd3..66f91bc145 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -1,4 +1,3 @@ -import axios from 'axios'; import { mediaUrl, gettext, serviceURL, siteRoot, isPro, fileAuditEnabled, canGenerateShareLink, canGenerateUploadLink, shareLinkPasswordMinLength, username, folderPermEnabled, onlyofficeConverterExtensions, enableSeadoc, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured, isSystemStaff, enableOnlyoffice, onlyofficeEditFileExtension, @@ -1998,7 +1997,3 @@ export const throttle = (func, delay) => { export const getType = (value) => { return Object.prototype.toString.call(value).slice(8, -1); }; - -export const isCanceled = (error) => { - return axios.isCancel(error); -};