Skip to content

Commit

Permalink
Merge pull request #6303 from nextcloud/enh/add-windows-incompatible-…
Browse files Browse the repository at this point in the history
…error-message

fix(attachmentService, propfindErrorParse): add an error message for when a file is not compatible for windows
  • Loading branch information
GVodyanov authored Sep 2, 2024
2 parents 702437f + d7288b0 commit b4d0a91
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/services/attachmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { generateOcsUrl, generateRemoteUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { parseXML } from 'webdav'
import { parseUploadError } from '../utils/propfindErrorParse.js'

/**
* Makes a share link for a given file or directory.
Expand Down Expand Up @@ -136,10 +137,17 @@ const uploadLocalAttachment = async function(folder, files, dav, componentAttach
}))
attachments.push(data)
}
}).catch(() => {
showError(t('calendar', 'An error occurred during uploading file {fileName}', {
fileName: file.name,
}))
}).catch(async (exception) => {
if (exception.response) {
const message = await parseUploadError(exception)
if (message) {
showError(message)
} else {
showError(t('calendar', 'An error occurred during uploading file {fileName}', {
fileName: file.name,
}))
}
}
})
promises.push(res)
}
Expand Down
28 changes: 28 additions & 0 deletions src/utils/propfindErrorParse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { t } from '@nextcloud/l10n'

/**
* Parse PROPFIND error when uploading a file and return a readable message.
*
* @param exception the error object
*/
async function parseUploadError(exception) {
try {
const responseText = await exception.response.data
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'), parseError)
}
}

export {
parseUploadError,
}

0 comments on commit b4d0a91

Please sign in to comment.