[MM-49088] Catching file upload issue when the response doesn't contain JSON (#23654)

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Cooke
2023-06-13 15:56:11 -04:00
коммит произвёл GitHub
родитель 0d81e5eb40
Коммит eb8efc59cc

Просмотреть файл

@@ -88,10 +88,15 @@ export function uploadFile({file, name, type, rootId, channelId, clientId, onPro
onSuccess(response, channelId, rootId);
} else if (xhr.status >= 400 && xhr.readyState === 4) {
const errorResponse = JSON.parse(xhr.response);
const errorMessage =
let errorMessage = '';
try {
const errorResponse = JSON.parse(xhr.response);
errorMessage =
(errorResponse?.id && errorResponse?.message) ? localizeMessage(errorResponse.id, errorResponse.message) :
localizeMessage('file_upload.generic_error', 'There was a problem uploading your files.');
} catch (e) {
errorMessage = localizeMessage('file_upload.generic_error', 'There was a problem uploading your files.');
}
dispatch({
type: FileTypes.UPLOAD_FILES_FAILURE,