[HOLD for payment 2021-11-22] Profile - Uploading a non-image file will show infinite loading and blocks the user from uploading a new profile picture
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Navigate to settings
- Click on Profile
- Click on the edit icon in the avatar
- On the file browser, select to display all files
- Select a non-image file
Expected Result:
There should be a message about a invalid file uploaded.
Actual Result:
There's an infinite loading displayed under the avatar icon. No option to upload a new image is displayed.
Workaround:
None found. Refreshing doesn't fix the issue. Only logging out and back will remove the infinite loading.
Platform:
Where is this issue occurring?
- Web
Version Number: 1.1.3-0
Reproducible in staging?: yes Reproducible in production?: yes
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
https://user-images.githubusercontent.com/44479856/135350563-03de1a78-73bb-42c2-9dd0-8b899d29c7fd.mp4
Expensify/Expensify Issue URL:
Issue reported by: @hanaffi Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1632870641227600
Triggered auto assignment to @yuwenmemon (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Proposed Solution: (If considered as external)
There are two problem here:
First is Non Image file (e.g. txt) Uploaded:
i.e. Whenever Non Image file uploaded at that time API.User_UploadAvatar() api throws error as
{jsonCode: 404, message: 'Invalid file. Please try a different image.', requestID: '69771aaa7f83697d-YVR'}
OR Sometimes return response within .then() block as
{jsonCode: 502, message: 'PDF Box can not upload user asset, requestID: '69771c200bbe31d0-YVR'}
I am not sure why sometime api throw error with {jsonCode: 404, ... } OR Sometime returns response with {jsonCode: 502, ... }. May be server side issue or maintenance. So I suggested solution that will handle all situation.
Second is Unsupported Image Uploaded:
i.e. Whenever SVG image Uploaded at that time API.User_UploadAvatar() returns response within .then() block as
{jsonCode: 502, message: 'PDF Box can not upload user asset, requestID: '69771c200bbe31d0-YVR'}
So in both case it goes to loading state because we are just handling (response.jsonCode === 200) and there is no .catch() block within setAvatar() action in src/libs/actions/PersonalDetails.js file as shown under:
https://github.com/Expensify/App/blob/fa7cb605574f1ddd147615eb070d828985dfc20a/src/libs/actions/PersonalDetails.js#L273-L281
So we have to update setAvatar() actions as under within src/libs/actions/PersonalDetails.js file:
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) {
setPersonalDetails({avatar: response.s3url, avatarUploading: false}, true);
} else {
setPersonalDetails({avatarUploading: false});
Growl.show(translateLocal('profilePage.avatarUploadFailureMessage'), CONST.GROWL.ERROR, 3000);
}
})
.catch((error) => {
setPersonalDetails({avatarUploading: false});
if (error.jsonCode === 404) {
Growl.show(translateLocal('profilePage.invalidFileMessage'), CONST.GROWL.ERROR, 3000);
} else {
Growl.show(translateLocal('profilePage.avatarUploadFailureMessage'), CONST.GROWL.ERROR, 3000);
}
});
}
Also within language file we have to add translation as under: src/languages/en.js
profilePage: {
...,
invalidFileMessage: 'Invalid file. Please try a different image.',
avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.',
},
src/languages/es.js
profilePage: {
...,
invalidFileMessage: 'Archivo inválido. Pruebe con una imagen diferente.',
avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.',
},
Below is screen record, How it works after update:
https://user-images.githubusercontent.com/7823358/135664939-687353e8-1a28-4632-bc5e-c13b295335c0.mov
This can be worked on by a contributor.
Triggered auto assignment to @dylanexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Working on this now!
Posted!
Internal: https://www.upwork.com/ab/applicants/1445266428359061504/job-details External: https://www.upwork.com/jobs/~01bf3c369a15b3262e
Triggered auto assignment to @thienlnam (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@dylanexpensify, If my suggested solution https://github.com/Expensify/App/issues/5593#issuecomment-932443740 work then kindly accept my proposal on upwork. So I can proceed to submit pr.
please accept my proposal so that I can work according to your requirements
@PrashantMangukiya Great proposal and good catch on the handling with the .catch and the .then. This solution works but as you mentioned we have some server side handling that will sometimes not throw the error. That's something I will look into internally but for your proposal, lets only keep the handling in .catch and remove the if/else in the .then
@gaurav27ats Thanks for your interest! Please read over https://github.com/Expensify/App/blob/main/CONTRIBUTING.md#working-on-expensify-jobs for future reference as you'll need to propose a solution in the Github issue
@thienlnam Thank you for the message. Below is the updated solution.
Existing code for setAvatar() is as under: https://github.com/Expensify/App/blob/fa7cb605574f1ddd147615eb070d828985dfc20a/src/libs/actions/PersonalDetails.js#L273-L281
Solution: We have to add .catch() block within setAvatar() actions, .then() block logic remain as it is.
Note: Previously I suggested else condition within then() block. Now no else condition in .then() block. So server side team please make sure to throw error() with 404 in case of invalid file etc. so it can be handled via catch() block.
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) {
setPersonalDetails({avatar: response.s3url, avatarUploading: false}, true);
}
})
.catch((error) => {
setPersonalDetails({avatarUploading: false});
if (error.jsonCode === 404) {
Growl.show(translateLocal('profilePage.invalidFileMessage'), CONST.GROWL.ERROR, 3000);
} else {
Growl.show(translateLocal('profilePage.avatarUploadFailureMessage'), CONST.GROWL.ERROR, 3000);
}
});
}
We have to add translation within src/languages/en.js:
profilePage: {
...,
invalidFileMessage: 'Invalid file. Please try a different image.',
avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.',
},
We have to add translation within src/languages/es.js:
profilePage: {
...,
invalidFileMessage: 'Archivo inválido. Pruebe con una imagen diferente.',
avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.',
},
If this solution ok then please message once we are ready to move forward. So I will proceed to submit pr.
Please refer to this post for updated information on the n6 hold, we've raised the bonus to $250 for all issues where a PR is created before the N6 hold is lifted.
@PrashantMangukiya Thanks, that looks good 🟢 on the job - @dylanexpensify Could you please hire @PrashantMangukiya for the job and assign him on this issue?
On it!
@PrashantMangukiya sent offer!
@dylanexpensify I accepted offer and proceed to submit pr soon. Thank you.
Hi @thienlnam,
I am preparing pr and testing with latest dev version v1.1.7-16 I noticed that server side api still return jsonCode 502 within .then() block when I upload invalid image/file (e.g. txt, svg etc.).
In my initial proposal https://github.com/Expensify/App/issues/5593#issuecomment-932443740 I put else condition within .then() to handle jsonCode other than 200. And within my updated proposal https://github.com/Expensify/App/issues/5593#issuecomment-934851578 I removed else condition from .then() block as per your suggestion https://github.com/Expensify/App/issues/5593#issuecomment-934661202
So during invalid image/file upload (e.g. txt, svg etc.) stil server side api returning jsonCode 502 within then() block and we decided to not use else{} condition within then() block, So at this moment 502 not handled and it goes to infinite loading as shown screenshot under:
So I am wandering what should I do now
Should I put else condition within .then() block as per my initial proposal https://github.com/Expensify/App/issues/5593#issuecomment-932443740 and submit pr ?
OR
Should I wait for server side api correction (i.e. server side api throw error that will handled via catch() block) And once server side correction done and informed to me, thereafter I will do final testing and submit PR?
Please let me know what you are suggesting. Thanks.
I think you should handle the wrong codes in then block and even if you want to catch them, then throw them so that they propagate to catch.
API will always respond with 200 HTTP code until something went wrong with the server or Network issue and errors are handled internally with jsonCode field. If you know that API throws 400 and 502. then you can handle both. Right?
@parasharrajat thanks for the suggestion.
I was also thinking to use else{} condition in then() block as per my initial proposal here https://github.com/Expensify/App/issues/5593#issuecomment-932443740 So it will handle jsonCode other than 200.
Yes if we know how many code it throw then we can handle it accordingly. But at present I do not know how many jsonCode throws by api as I came across 502 most of time in then() block, and 404 in catch() block, so I suggested initial solution accordingly.
@parasharrajat @thienlnam do you have idea whose confirmation need to use else{} condition in then block etc. I am waiting for confirmation from someone who authorised.
Thanks.