[HOLD for payment 2022-01-11] [Network] No error messages shown to user when setpassword gets an error from the API
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:
sign up as a new user and click the link. Delete the last character of the url and navigate.
Expected Result:
An error should be shown to the user explaining why the request didn't work. In this case say the key has likely expired and a new one will be waiting in their emails. I would also expect the email from expensify to be another link to new.expensify.com to finish the set password flow
Actual Result:
https://user-images.githubusercontent.com/47184118/129949187-00c5b590-ca4e-4a7a-abee-54b49ece9952.mp4 the second email has a link to the old expensify password reset flow, not to the new.expensify.com/setpassword/.../...
Workaround:
User would have to guess what went wrong (I'm simulating an expired token). User would have to check emails finish the flow in the old site and then navigate to the new site.
Platform:
- Web
- iOS
- Android
- Desktop App
- Mobile Web
Triggered auto assignment to @tjferriss (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.
should I made another issue for the API not sending the correct link out or will that get one made internally somewhere else?
I reported a duplicate issue it seems. I am proposing the following solution.
Proposed Solution
Add a catch block to setPassword API:
function setPassword(password, validateCode, accountID) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});
API.SetPassword({
password,
validateCode,
accountID,
})
.then((response) => {
/// existing code
})
.catch((err) => {
Onyx.merge(ONYXKEYS.ACCOUNT, {error: err.message});
})
// existing code
}

@tjferriss Huh... This is 4 days overdue. Who can take care of this?
I would modify: https://github.com/Expensify/App/blob/8a5cf2d190e8e259a1bcb4090fcb437e42f78dbe/src/libs/actions/Session.js#L261-L281 To resemble: https://github.com/Expensify/App/blob/8a5cf2d190e8e259a1bcb4090fcb437e42f78dbe/src/libs/actions/Session.js#L229-L231
Where the error handling would be in a catch block. I'm not familiar with translateLocal yet. I would look at using this on the error as well.
I had a look at how API.js handles it and we have a bunch of switch cases to cover off giving the right translated strings in the Errors to give to translateLocal: https://github.com/Expensify/App/blob/8a5cf2d190e8e259a1bcb4090fcb437e42f78dbe/src/libs/API.js#L222-L251
Do we have such sophistication of HTTP codes for this API call?
For a simple fix I can just use the message in the API response to display. But to bring this upto standard with the rest of the app with translations I need a mapping of the different HTTP error codes to copy.
The API response not being translated should be its own issue. I'll make one later :)
@tjferriss 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
@tjferriss 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!
@akshayasalvi can you link to the duplicate issue you previously mentioned? If you're working on a solution there then can we close this issue?
@tjferriss the issue is #4745 . I am not working on it at the moment. One of your team member asked me to apply to this issue and closed the other one .
here’s my proposal for the same https://github.com/Expensify/App/issues/4737#issuecomment-903034853
Thanks for referencing it and sorry for the delay here. I'm going to tag engineering so someone can take a look and remove my assignment.
Triggered auto assignment to @chiragsalian (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Triggered auto assignment to @kadiealexander (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Nice issue. Yes, let's improve it.
should I made another issue for the API not sending the correct link out or will that get one made internally somewhere else?
I don't follow. Can you explain this API? If its for a new link, that's not needed, we have the email in localStorage and when you redirect to the screen i mentioned below you would use the same email.
But to bring this upto standard with the rest of the app with translations I need a mapping of the different HTTP error codes to copy.
We unfortunately do not have such mapping.
I'm not sure I'm a fan of either solution. The solution posts an error message but does not help the user with their next step. The behavior of the solution should be very similar to what we do in expensify.com i.e., when the validate code is incorrect we show,

So the copy we want to use is -
It looks like there was an error with your validation link. Either the validation link has expired, or your account does not exist.
So this means for newDot we'll want to redirect to this screen with the correct error message,

With that in mind can you guys come up with an updated proposal?
Updated Proposal
Based on the feedback, we could do the following:
function setPassword(password, validateCode, accountID) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});
API.SetPassword({
password,
validateCode,
accountID,
})
.then((response) => {
/// existing code
})
.catch((err) => {
if(err.statusCode === 404) {
Onyx.merge(ONYXKEYS.ACCOUNT, { hasValidationCodeError: true});
Navigation.navigate(ROUTES.HOME);
}
})
// existing code
}
and in the SigninPage
const validAccount = this.props.account.accountExists
&& this.props.account.validated
&& !this.props.account.forgotPassword && !this.props.account.hasValidationCodeError;
const hasValidationCodeError = this.props.credentials.login
&& !validAccount
&& this.props.account.hasValidationCodeError
const welcomeText = this.props.translate(`${hasValidationCodeError ? 'resendValidationForm.validationCodeExpired': `welcomeText.${showPasswordForm ? 'phrase4' : 'phrase1'`);
{showResendValidationLinkForm && <ResendValidationForm />}
and finally, update the translations:
en: {
resendValidationForm: {
validationCodeExpired: 'It looks like there was an error with your validation link. Either the validation link has expired, or your account does not exist.'
},
},
es: {
resendValidationForm: {
validationCodeExpired:'Spanish Translation'
}
}
One suggestion is that the text message looks too big. Can we shorten it a bit?
Upwork post: https://www.upwork.com/jobs/~019934453904b5ea8f
@akshayasalvi, nice i like that direction. Few suggestions:
- I don't see the need for
hasValidationCodeErrorboolean when we already havethis.props.account.validatedthat we can reuse. This would clean up the logic ofvalidAccountand not needhasValidationCodeError. - With the changes from above if we don't pass
hasValidationCodeErrorwe can instead pass a stringvalidationFailedMessage(maybe check if you can reuse account.error first before this new key). This can be reused in the future too if needed and cleans up some of the current logic. So with those changes, i would suggest doing,
Onyx.merge(ONYXKEYS.ACCOUNT, { validated: false, validationFailedMessage: 'resendValidationForm.validationCodeExpired'});
- Next the welcomeText variable is not very readable in my opinion. Having double ternary operator in a single line is not very readable so if we pass
resendValidationForm.validationCodeExpiredasvalidationFailedMessagethen we can clean this up like so,
const welcomeText = this.props.translate(this.props.account.validationFailedMessage ?? (`welcomeText.${showPasswordForm ? 'phrase4' : 'phrase1'}`));
- But while we can clean that up as I think about this, we shouldn't be editing the
welcomeText. In fact i think welcomeText should be blank and we should instead update the code here to displayresendValidationForm.validationCodeExpiredinstead ofresendValidationForm.weSentYouMagicSignInLinkwhenvalidationFailedMessagecontains a value i.e.,
this.props.account.validationFailedMessage ?? 'resendValidationForm.weSentYouMagicSignInLink'
- To answer "One suggestion is that the text message looks too big. Can we shorten it a bit?" I think its pretty small. Once we've got the PR up we can revisit the copy if it still looks too long in the UI.
Thoughts on these changes @akshayasalvi?
Good points overall. I wasn't sure if we allow adding translation keys in Onyx. Agree with points 1, 2, 3, and 5.
Point 4, I feel without the title this page will look off compared to other pages. But let's try and see how it shows up. Sounds okay?
Yup all those sounds good with me. @kadiealexander, can you hire @akshayasalvi in upwork. @akshayasalvi, feel free to go ahead and work on the PR.