diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index 2c9d66813c8..49f7269bd0e 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -26,6 +26,7 @@ import { getFileNamePrompt, separateDuplicateUploads, } from '../utils/fileUpload.js' +import { parseUploadError } from '../utils/propfindErrorParse.ts' const state = { attachmentFolder: loadState('spreed', 'attachment_folder', ''), @@ -349,7 +350,14 @@ const actions = { context.commit('markFileAsPendingUpload', { uploadId, index, sharePath: uniquePath }) } catch (exception) { console.error(`Error while uploading file "${fileName}":` + exception.message, fileName) - showError(t('spreed', 'Error while uploading file "{fileName}"', { fileName })) + if (exception.response) { + const message = await parseUploadError(exception) + if (message) { + showError(message) + } else { + showError(t('spreed', 'Error while uploading file "{fileName}"', { fileName })) + } + } // Mark the upload as failed in the store context.commit('markFileAsFailedUpload', { uploadId, index }) const { id } = uploadedFile.temporaryMessage diff --git a/src/utils/propfindErrorParse.ts b/src/utils/propfindErrorParse.ts new file mode 100644 index 00000000000..f5ea9a33bf9 --- /dev/null +++ b/src/utils/propfindErrorParse.ts @@ -0,0 +1,34 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { t } from '@nextcloud/l10n' + +type PROPFINDException = { + response: { + text: () => Promise + } +} + +/** + * Parse PROPFIND error when uploading a file and return a readable message. + * + * @param exception error object + */ +async function parseUploadError(exception : PROPFINDException) { + try { + const responseText = await exception.response.text() + const parser = new DOMParser() + const xmlDoc = parser.parseFromString(responseText, 'application/xml') + const messageElement = xmlDoc.getElementsByTagName('s:message')[0] + + return messageElement?.textContent + } catch (parseError) { + console.error(t('spreed', 'Error while parsing a PROPFIND error')) + } +} + +export { + parseUploadError, +}