diff --git a/src/languages/en.js b/src/languages/en.js index 720cd18ce112..704ed6785814 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -232,6 +232,8 @@ export default { setMyTimezoneAutomatically: 'Set my timezone automatically', timezone: 'Timezone', growlMessageOnSave: 'Your profile was successfully saved', + invalidFileMessage: 'Invalid file. Please try a different image.', + avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.', online: 'Online', offline: 'Offline', syncing: 'Syncing', diff --git a/src/languages/es.js b/src/languages/es.js index 0e1749838482..349af9efc327 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -232,6 +232,8 @@ export default { setMyTimezoneAutomatically: 'Configura mi zona horaria automáticamente', timezone: 'Zona horaria', growlMessageOnSave: 'Tu perfil se ha guardado correctamente', + invalidFileMessage: 'Archivo inválido. Pruebe con una imagen diferente.', + avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.', online: 'En línea', offline: 'Desconectado', syncing: 'Sincronizando', diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 3cd6365326b9..d46e2b7c52b3 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -302,12 +302,24 @@ function fetchLocalCurrency() { */ function setAvatar(file) { setPersonalDetails({avatarUploading: true}); - API.User_UploadAvatar({file}).then((response) => { - // Once we get the s3url back, update the personal details for the user with the new avatar URL - if (response.jsonCode === 200) { + API.User_UploadAvatar({file}) + .then((response) => { + // Once we get the s3url back, update the personal details for the user with the new avatar URL + if (response.jsonCode !== 200) { + const error = new Error(); + error.jsonCode = response.jsonCode; + throw error; + } setPersonalDetails({avatar: response.s3url, avatarUploading: false}, true); - } - }); + }) + .catch((error) => { + setPersonalDetails({avatarUploading: false}); + if (error.jsonCode === 405 || error.jsonCode === 502) { + Growl.show(translateLocal('profilePage.invalidFileMessage'), CONST.GROWL.ERROR, 3000); + } else { + Growl.show(translateLocal('profilePage.avatarUploadFailureMessage'), CONST.GROWL.ERROR, 3000); + } + }); } /**