Skip to content
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
10 changes: 9 additions & 1 deletion src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getFileNamePrompt,
separateDuplicateUploads,
} from '../utils/fileUpload.js'
import { parseUploadError } from '../utils/propfindErrorParse.ts'

const state = {
attachmentFolder: loadState('spreed', 'attachment_folder', ''),
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/utils/propfindErrorParse.ts
Original file line number Diff line number Diff line change
@@ -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<string>
}
}

/**
* 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,
}