-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed Improvements to error messaging issue #1091 #1166
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed everything. It was set via prettify formatter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the linter failures. If you look at the rest of the code base you'll see that we use four-space indentation everywhere. Please do the same for src/libs/ErrorMessage/messages.js
Thanks for letting me. I've fixed linter failures. Can you please review it now. |
@@ -0,0 +1,31 @@ | |||
const erroMessages = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, You can verify please.
src/libs/ErrorMessage/index.js
Outdated
import errorMessages from './errorMessages'; | ||
|
||
/** | ||
* It's generic function to print any messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the generic aspect of this. It's over-engineering. Right now we just need to handle error messages better in the context of Authenticate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, You can verify please.
Here is the details of the changes. Also, I have modified a file src\libs\actions\Session.js where we call the getErrorMessage function. After that, I have changed this code for calling the error with one parameter and changed the
Please let me know if you have any questions. |
src/libs/ErrorMessage/index.js
Outdated
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |||
import errorMessages from './errorMessages'; | |||
|
|||
/** | |||
* It's generic function to print any messages. | |||
* It's function to print handle error messages in the context of Authenticate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo? print handle error messages
is awkward. Probably should be either/or.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deetergp Okay, I think, It will be better. This function is handling error messages for the Authentication.
else can you advise on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of the day, shouldn't your naming explain the "what" and your docs and comments explain the "why"? Like shouldn't function be called getFriendlyErrorMessage
and the doc comment should briefly summarize the reason we need the function like Display a user-friendly message in the UI when the API returns an authentication error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deetergp Okay, Should we change with this Display a error message in the UI when the API returns an authentication error.
?
If it works, please let me know. I'll change it. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devkashan1 I meant to move this logic to the context of Authenticate
(in src/libs/Api.js) since that's the only spot where it's relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuwenmemon Thanks for the clarification. I just have pushed the changes. You can verify now.
src/libs/ErrorMessage/index.js
Outdated
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |||
import errorMessages from './errorMessages'; | |||
|
|||
/** | |||
* It's generic function to print any messages. | |||
* It's function to print handle error messages in the context of Authenticate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of the day, shouldn't your naming explain the "what" and your docs and comments explain the "why"? Like shouldn't function be called getFriendlyErrorMessage
and the doc comment should briefly summarize the reason we need the function like Display a user-friendly message in the UI when the API returns an authentication error
.
src/libs/ErrorMessage/index.js
Outdated
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |||
import errorMessages from './errorMessages'; | |||
|
|||
/** | |||
* It's generic function to print any messages. | |||
* It's function to print handle error messages in the context of Authenticate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devkashan1 I meant to move this logic to the context of Authenticate
(in src/libs/Api.js) since that's the only spot where it's relevant.
* @param {String} error | ||
* @returns {String} | ||
*/ | ||
function GetSignInErrorMessage(error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah what I meant was that you should probably place this in Authenticate
. I also think you don't need a separate authenticationErrorMessages file either. It's overkill for what we're trying to achieve IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I understood where you mentioned place in Authenticate
. This means in src\libs\actions\Session.js
file. So, This function GetSignInErrorMessage
should be in this src\libs\actions\Session.js
file, and no need separate file for authenticationErrorMessages
. If you confirm me so I can proceed the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuwenmemon Could you please confirm so I can push and close it?
Closing this PR as a solution was already merged |
The details of the implementation for this problem that I have fixed in the project as I briefed above:
I have added a new file where we can manage any error messages at this place
src\libs\ErrorMessage\messages.js.
I have also added another file where I created a function to fetch the appropriate message via type and error code. The path is
src\libs\ErrorMessage\index.js.
After these, I have modified a file
src\libs\actions\Session.js
where we call thegetErrorMessage
function.Line #11:
import {getErrorMessage} from '../ErrorMessage';
Line #162:
Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message)});
Line #169:
Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message), loading: false});
That's all.