Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable5.0] fix(attachmentService, propfindErrorParse): add an error message for when a file is not compatible for windows #6311

Merged
merged 1 commit into from
Sep 2, 2024
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
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 { 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 @@
}))
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,
}
Loading