Skip to content

Commit

Permalink
fix(attachmentService, propfindErrorParse): add an error message for …
Browse files Browse the repository at this point in the history
…when a file is not compatible for windows

Signed-off-by: Grigory Vodyanov <[email protected]>
  • Loading branch information
GVodyanov committed Sep 2, 2024
1 parent 38b658d commit d7288b0
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) => {

Check warning on line 140 in src/services/attachmentService.js

View check run for this annotation

Codecov / codecov/patch

src/services/attachmentService.js#L140

Added line #L140 was not covered by tests
if (exception.response) {
const message = await parseUploadError(exception)

Check warning on line 142 in src/services/attachmentService.js

View check run for this annotation

Codecov / codecov/patch

src/services/attachmentService.js#L142

Added line #L142 was not covered by tests
if (message) {
showError(message)
} else {
showError(t('calendar', 'An error occurred during uploading file {fileName}', {

Check warning on line 146 in src/services/attachmentService.js

View check run for this annotation

Codecov / codecov/patch

src/services/attachmentService.js#L144-L146

Added lines #L144 - L146 were not covered by tests
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]

Check warning on line 18 in src/utils/propfindErrorParse.js

View check run for this annotation

Codecov / codecov/patch

src/utils/propfindErrorParse.js#L13-L18

Added lines #L13 - L18 were not covered by tests

return messageElement?.textContent

Check warning on line 20 in src/utils/propfindErrorParse.js

View check run for this annotation

Codecov / codecov/patch

src/utils/propfindErrorParse.js#L20

Added line #L20 was not covered by tests
} catch (parseError) {
console.error(t('spreed', 'Error while parsing a PROPFIND error'), parseError)

Check warning on line 22 in src/utils/propfindErrorParse.js

View check run for this annotation

Codecov / codecov/patch

src/utils/propfindErrorParse.js#L22

Added line #L22 was not covered by tests
}
}

export {
parseUploadError,
}

0 comments on commit d7288b0

Please sign in to comment.