Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not import from axios but only @nextcloud/axios #45161

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { action } from './deleteAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission, View, FileAction } from '@nextcloud/files'
import eventBus from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
import eventBus from '@nextcloud/event-bus'

import logger from '../logger'

Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/favoriteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import { action } from './favoriteAction'
import { expect } from '@jest/globals'
import { File, Permission, View, FileAction } from '@nextcloud/files'
import axios from '@nextcloud/axios'
import eventBus from '@nextcloud/event-bus'
import * as favoriteAction from './favoriteAction'
import axios from '@nextcloud/axios'
import logger from '../logger'

const view = {
Expand Down
15 changes: 7 additions & 8 deletions apps/files/src/actions/moveOrCopyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import type { IFilePickerButton } from '@nextcloud/dialogs'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import type { MoveCopyResult } from './moveOrCopyActionUtils'

// eslint-disable-next-line n/no-extraneous-import
import { AxiosError } from 'axios'
import { basename, join } from 'path'
import { emit } from '@nextcloud/event-bus'
import { isAxiosError } from '@nextcloud/axios'
import { FilePickerClosed, getFilePickerBuilder, showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { Permission, FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { openConflictPicker, hasConflict } from '@nextcloud/upload'
import { basename, join } from 'path'
import Vue from 'vue'

import CopyIconSvg from '@mdi/svg/svg/folder-multiple.svg?raw'
Expand Down Expand Up @@ -151,12 +150,12 @@ export const handleCopyMoveNodeTo = async (node: Node, destination: Folder, meth
emit('files:node:deleted', node)
}
} catch (error) {
if (error instanceof AxiosError) {
if (error?.response?.status === 412) {
if (isAxiosError(error)) {
if (error.response?.status === 412) {
throw new Error(t('files', 'A file or folder with that name already exists in this folder'))
} else if (error?.response?.status === 423) {
} else if (error.response?.status === 423) {
throw new Error(t('files', 'The files are locked'))
} else if (error?.response?.status === 404) {
} else if (error.response?.status === 404) {
throw new Error(t('files', 'The file does not exist anymore'))
} else if (error.message) {
throw new Error(error.message)
Expand Down
3 changes: 1 addition & 2 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import { emit } from '@nextcloud/event-bus'
import { FileType, NodeStatus, Permission } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import { isAxiosError } from 'axios'
import axios, { isAxiosError } from '@nextcloud/axios'
import Vue, { defineComponent } from 'vue'

import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// eslint-disable-next-line n/no-extraneous-import
import type { AxiosResponse } from 'axios'
import type { AxiosResponse } from '@nextcloud/axios'
import type { Node } from '@nextcloud/files'
import type { StorageConfig } from '../services/externalStorage'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// eslint-disable-next-line n/no-extraneous-import
import type { AxiosError } from 'axios'
import type { AxiosError } from '@nextcloud/axios'
import type { Node } from '@nextcloud/files'

import { showWarning } from '@nextcloud/dialogs'
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/src/services/externalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// eslint-disable-next-line n/no-extraneous-import
import type { AxiosResponse } from 'axios'
import type { AxiosResponse } from '@nextcloud/axios'
import type { ContentsWithRoot } from '@nextcloud/files'
import type { OCSResponse } from '@nextcloud/typings/ocs'

Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/services/SharingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/* eslint-disable camelcase, n/no-extraneous-import */
import type { AxiosPromise } from 'axios'
import type { AxiosPromise } from '@nextcloud/axios'
import type { OCSResponse } from '@nextcloud/typings/ocs'

import { Folder, File, type ContentsWithRoot, Permission } from '@nextcloud/files'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import debounce from 'debounce'
import { mdiArrowLeft, mdiLock, mdiStar, mdiStarOutline, mdiTrashCan } from '@mdi/js'

import FederationControl from '../shared/FederationControl.vue'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants.js'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import HeaderBar from '../shared/HeaderBar.vue'
import { ACCOUNT_PROPERTY_READABLE_ENUM, DEFAULT_ADDITIONAL_EMAIL_SCOPE, NAME_READABLE_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryEmail, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService.js'
import { validateEmail } from '../../../utils/validate.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

const { emailMap: { additionalEmails, primaryEmail, notificationEmail } } = loadState('settings', 'personalInfoParameters', {})
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { validateLanguage } from '../../../utils/validate.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import MapClock from 'vue-material-design-icons/MapClock.vue'

import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

export default {
name: 'Locale',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { emit } from '@nextcloud/event-bus'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

export default {
name: 'ProfileCheckbox',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'

import { saveProfileParameterVisibility } from '../../../service/ProfileService.js'
import { VISIBILITY_PROPERTY_ENUM } from '../../../constants/ProfileConstants.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

const { profileEnabled } = loadState('settings', 'personalInfoParameters', false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'
import HeaderBar from './HeaderBar.vue'

import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

export default {
name: 'AccountPropertySection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
UNPUBLISHED_READABLE_PROPERTIES,
} from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { handleError } from '../../../utils/handlers.js'
import { handleError } from '../../../utils/handlers.ts'

const {
federationEnabled,
Expand Down
5 changes: 2 additions & 3 deletions apps/settings/src/service/WebAuthnRegistrationSerice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { startRegistration as registerWebAuthn } from '@simplewebauthn/browser'

import Axios from 'axios'
import axios from '@nextcloud/axios'
import axios, { isAxiosError } from '@nextcloud/axios'
import logger from '../logger'

/**
Expand All @@ -28,7 +27,7 @@ export async function startRegistration() {
return attrs
} catch (e) {
logger.error(e as Error)
if (Axios.isAxiosError(e)) {
if (isAxiosError(e)) {
throw new Error(t('settings', 'Could not register device: Network error'))
} else if ((e as Error).name === 'InvalidStateError') {
throw new Error(t('settings', 'Could not register device: Probably already registered'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { AxiosError } from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'

import logger from '../logger.ts'

/**
* @param {import('axios').AxiosError} error the error
* @param {string?} message the message to display
* @param error the error
* @param message the message to display
*/
export const handleError = (error, message) => {
export function handleError(error: AxiosError, message: string) {
let fullMessage = ''

if (message) {
Expand All @@ -26,6 +27,7 @@ export const handleError = (error, message) => {
fullMessage += t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.')
}

fullMessage = fullMessage || t('settings', 'Error')
showError(fullMessage)
logger.error(fullMessage || t('Error'), error)
logger.error(fullMessage, { error })
}
11 changes: 4 additions & 7 deletions dist/1642-1642.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/auth
- version: 2.3.0
- license: GPL-3.0-or-later
- @nextcloud/router
- version: 2.2.0
- license: GPL-3.0-or-later
- @nextcloud/axios
- version: 2.4.0
- version: 2.5.0
- license: GPL-3.0-or-later
- semver
- version: 7.6.2
Expand All @@ -62,6 +59,9 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/logger
- version: 2.7.0
- license: GPL-3.0-or-later
- core-js
- version: 3.33.0
- license: MIT
- debounce
- version: 2.0.0
- license: MIT
Expand Down Expand Up @@ -95,9 +95,6 @@ This file is generated from multiple sources. Included packages:
- console-browserify
- version: 1.2.0
- license: MIT
- core-js
- version: 3.37.1
- license: MIT
- css-loader
- version: 6.10.0
- license: MIT
Expand Down
Loading
Loading