From eb8efc59cc37a5308c03eefdb5e4a45ac9a98e35 Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Tue, 13 Jun 2023 15:56:11 -0400 Subject: [PATCH] [MM-49088] Catching file upload issue when the response doesn't contain JSON (#23654) Co-authored-by: Mattermost Build --- webapp/channels/src/actions/file_actions.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/webapp/channels/src/actions/file_actions.ts b/webapp/channels/src/actions/file_actions.ts index 73c33f35e7..0804ed3c1d 100644 --- a/webapp/channels/src/actions/file_actions.ts +++ b/webapp/channels/src/actions/file_actions.ts @@ -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,