Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

devkashan1
Copy link

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 the getErrorMessage 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.

@devkashan1 devkashan1 requested a review from a team as a code owner January 4, 2021 20:48
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@botify botify requested review from deetergp and removed request for a team January 4, 2021 20:48
@devkashan1
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Author

@devkashan1 devkashan1 left a 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.

Copy link
Contributor

@deetergp deetergp left a 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

@devkashan1
Copy link
Author

devkashan1 commented Jan 8, 2021

Thanks for letting me. I've fixed linter failures. Can you please review it now.

@@ -0,0 +1,31 @@
const erroMessages = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks

Copy link
Author

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.

import errorMessages from './errorMessages';

/**
* It's generic function to print any messages.
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Author

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.

@devkashan1
Copy link
Author

Here is the details of the changes.
Replace a file name src\libs\ErrorMessage\messages.js. to src\libs\ErrorMessage\errorMessages.js. due to avoid misunderstanding of naming.
I had removed the type parameter that was considering as generic but now we can pass only parameter getErrorMessage(error.message)

Also, I have modified a file src\libs\actions\Session.js where we call the getErrorMessage function.
Line #162: Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message)});
Line #169: Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message), loading: false});

After that, I have changed this code for calling the error with one parameter and changed the message obj to errorMessage in src\libs\ErrorMessage\index.js

function getErrorMessage(error) {
    const code = error.split(' ')[0];
    if (!_.isEmpty(code)) {
        const errorMessage = _.filter(errorMessages, {errorCode: +code.trim()});
        if (!_.isEmpty(errorMessage)) {
            return errorMessage[0].errorMessage;
        }
    }
    return error;
}
export default getErrorMessage;

Please let me know if you have any questions.

@@ -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.
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

@deetergp deetergp Jan 13, 2021

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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.

@@ -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.
Copy link
Contributor

@deetergp deetergp Jan 13, 2021

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.

@@ -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.
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Author

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?

@yuwenmemon
Copy link
Contributor

Closing this PR as a solution was already merged

@yuwenmemon yuwenmemon closed this Jan 19, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants