From 4a211b3e82008e619adf043a968cdc871570c67e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 16 Feb 2026 12:40:04 +0100 Subject: [PATCH] fix(files_sharing): ensure the server share API errors are shown - fix https://github.com/nextcloud/server/issues/58359 To reproduce: 1. Setup password policy. 2. Try to set a share password like `1234` 3. See that no visual error message is show but only in the console Signed-off-by: Ferdinand Thiessen --- .../files_sharing/src/mixins/ShareRequests.js | 59 +++++++++---------- package-lock.json | 16 ++--- package.json | 3 +- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/apps/files_sharing/src/mixins/ShareRequests.js b/apps/files_sharing/src/mixins/ShareRequests.js index 2c33fa3b0c7..4206a0135ec 100644 --- a/apps/files_sharing/src/mixins/ShareRequests.js +++ b/apps/files_sharing/src/mixins/ShareRequests.js @@ -3,15 +3,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -// TODO: remove when ie not supported -import 'url-search-params-polyfill' - -import { emit } from '@nextcloud/event-bus' +import axios, { isAxiosError } from '@nextcloud/axios' import { showError } from '@nextcloud/dialogs' +import { emit } from '@nextcloud/event-bus' import { generateOcsUrl } from '@nextcloud/router' -import axios from '@nextcloud/axios' - import Share from '../models/Share.ts' +import logger from '../services/logger.ts' const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares') @@ -45,13 +42,9 @@ export default { emit('files_sharing:share:created', { share }) return share } catch (error) { - console.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) { - console.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 }) } }, @@ -96,17 +85,27 @@ export default { return request.data.ocs.data } } catch (error) { - console.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) + logger.error('Error while updating share', { error }) + 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 + } + } +} diff --git a/package-lock.json b/package-lock.json index bdf23771104..09630055cc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,8 +70,7 @@ "snap.js": "^2.0.9", "strengthify": "github:nextcloud/strengthify#0.5.9", "throttle-debounce": "^5.0.2", - "underscore": "1.13.7", - "url-search-params-polyfill": "^8.1.1", + "underscore": "1.13.8", "v-click-outside": "^3.2.0", "v-tooltip": "^2.1.3", "vue": "^2.7.16", @@ -25479,9 +25478,10 @@ } }, "node_modules/underscore": { - "version": "1.13.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", - "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==" + "version": "1.13.8", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz", + "integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ==", + "license": "MIT" }, "node_modules/undici": { "version": "6.23.0", @@ -25796,12 +25796,6 @@ "requires-port": "^1.0.0" } }, - "node_modules/url-search-params-polyfill": { - "version": "8.2.5", - "resolved": "https://registry.npmjs.org/url-search-params-polyfill/-/url-search-params-polyfill-8.2.5.tgz", - "integrity": "sha512-FOEojW4XReTmtZOB7xqSHmJZhrNTmClhBriwLTmle4iA7bwuCo6ldSfbtsFSb8bTf3E0a3XpfonAdaur9vqq8A==", - "license": "MIT" - }, "node_modules/util": { "version": "0.12.5", "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", diff --git a/package.json b/package.json index 54b7a8df506..c50054e1f34 100644 --- a/package.json +++ b/package.json @@ -107,8 +107,7 @@ "snap.js": "^2.0.9", "strengthify": "github:nextcloud/strengthify#0.5.9", "throttle-debounce": "^5.0.2", - "underscore": "1.13.7", - "url-search-params-polyfill": "^8.1.1", + "underscore": "1.13.8", "v-click-outside": "^3.2.0", "v-tooltip": "^2.1.3", "vue": "^2.7.16",