Merge pull request #58360 from nextcloud/fix/show-error-sharing

fix(files_sharing): ensure the server share API errors are shown
This commit is contained in:
Ferdinand Thiessen 2026-02-19 17:16:43 +01:00 committed by GitHub
commit 21da74cade
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 112 additions and 333 deletions

View file

@ -3,16 +3,13 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import axios from '@nextcloud/axios'
import axios, { isAxiosError } from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { generateOcsUrl } from '@nextcloud/router'
import Share from '../models/Share.ts'
import logger from '../services/logger.ts'
// TODO: remove when ie not supported
import 'url-search-params-polyfill'
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
export default {
@ -45,13 +42,9 @@ export default {
emit('files_sharing:share:created', { share })
return share
} catch (error) {
logger.error('Error while creating share', { error })
const errorMessage = error?.response?.data?.ocs?.meta?.message
showError(
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
{ type: 'error' },
)
throw error
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error creating the share')
showError(errorMessage)
throw new Error(errorMessage, { cause: error })
}
},
@ -70,13 +63,9 @@ export default {
emit('files_sharing:share:deleted', { id })
return true
} catch (error) {
logger.error('Error while deleting share', { error })
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error deleting the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error deleting the share'),
{ type: 'error' },
)
throw error
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error deleting the share')
showError(errorMessage)
throw new Error(errorMessage, { cause: error })
}
},
@ -97,16 +86,26 @@ export default {
}
} catch (error) {
logger.error('Error while updating share', { error })
if (error.response.status !== 400) {
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error updating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error updating the share'),
{ type: 'error' },
)
}
const message = error.response.data.ocs.meta.message
throw new Error(message)
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error updating the share')
// the error will be shown in apps/files_sharing/src/mixins/SharesMixin.js
throw new Error(errorMessage, { cause: error })
}
},
},
}
/**
* Handle an error response from the server and show a notification with the error message if possible
*
* @param {unknown} error - The received error
* @return {string|undefined} the error message if it could be extracted from the response, otherwise undefined
*/
function getErrorMessage(error) {
if (isAxiosError(error) && error.response.data?.ocs) {
/** @type {import('@nextcloud/typings/ocs').OCSResponse} */
const response = error.response.data
if (response.ocs.meta?.message) {
return response.ocs.meta.message
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -79,7 +79,6 @@
"regenerator-runtime": "^0.14.1",
"throttle-debounce": "^5.0.2",
"underscore": "1.13.7",
"url-search-params-polyfill": "^8.2.5",
"v-click-outside": "^3.2.0",
"v-tooltip": "^2.1.3",
"vue": "^2.7.16",

4
dist/6980-6980.js vendored

File diff suppressed because one or more lines are too long

View file

@ -29,7 +29,6 @@ SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Jonas Schade <derzade@gmail.com>
SPDX-FileCopyrightText: Jerry Bendy <jerry@icewingcc.com>
SPDX-FileCopyrightText: Jeff Sagal <sagalbot@gmail.com>
SPDX-FileCopyrightText: James Halliday
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
@ -292,9 +291,6 @@ This file is generated from multiple sources. Included packages:
- unist-util-visit
- version: 5.1.0
- license: MIT
- url-search-params-polyfill
- version: 8.2.5
- license: MIT
- util-deprecate
- version: 1.0.2
- license: MIT

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long