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

Export multiple arguments of an error as an object to reduce import statements. #1038

Closed
anshgoyalevil opened this issue Feb 9, 2023 · 9 comments · Fixed by #1143
Closed
Assignees

Comments

@anshgoyalevil
Copy link
Contributor

Is your feature request related to a problem? Please describe.
This issue is related to the refactoring of code, where the multiple arguments of an error are being exported as separate constants. For example:

export const COMMENT_NOT_FOUND = "Comment not found";
export const COMMENT_NOT_FOUND_CODE = "comment.notFound";
export const COMMENT_NOT_FOUND_MESSAGE = "comment.notFound";
export const COMMENT_NOT_FOUND_PARAM = "comment";

this can be converted to an object like

export const COMMENT_NOT_FOUND_ERROR = {
  DESC: "Comment not found",
  CODE: "comment.notFound",
  MESSAGE: "comment.notFound",
  PARAM: "comment",
};

which can further be imported in the codebase as an object, and can replace the error constants such as

if (!comment) {
    throw new errors.NotFoundError(
      IN_PRODUCTION !== true
        ? COMMENT_NOT_FOUND
        : requestContext.translate(COMMENT_NOT_FOUND_MESSAGE),
      COMMENT_NOT_FOUND_CODE,
      COMMENT_NOT_FOUND_PARAM
    );
  }

with

if (!comment) {
    throw new errors.NotFoundError(
      IN_PRODUCTION !== true
        ? COMMENT_NOT_FOUND
        : requestContext.translate(COMMENT_NOT_FOUND_ERROR.MESSAGE),
      COMMENT_NOT_FOUND_ERROR.CODE,
      COMMENT_NOT_FOUND_ERROR.PARAM
    );
  }

Approach to be followed (optional)
The following approach can be followed:

  • Create the error objects.
  • Search the codebase for the usage of those constants, and replace them with those objects.

Additional context
This will reduce the complexity of codebase import statements, since there are a lot of import statements inside a code file, for the constant, which can be grouped together.

@github-actions github-actions bot added the unapproved Unapproved for Pull Request label Feb 9, 2023
@anshgoyalevil
Copy link
Contributor Author

anshgoyalevil commented Feb 9, 2023

@noman2002 @palisadoes Please take a look at this issue.

@KrutikaBhatt
Copy link
Contributor

In case it's fine, can I work on this issue?

@anshgoyalevil
Copy link
Contributor Author

In case it's fine, can I work on this issue?

Let's wait for others view on this. After that, we can create child issues for it, and work upon them.

@anshgoyalevil
Copy link
Contributor Author

@xoldyckk What's your view on this?

@xoldd
Copy link
Contributor

xoldd commented Feb 12, 2023

@anshgoyalevil It's a good idea.

@palisadoes palisadoes removed the unapproved Unapproved for Pull Request label Feb 13, 2023
@github-actions
Copy link

This issue did not get any activity in the past 14 days and will be closed in 365 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Feb 28, 2023
@anshgoyalevil anshgoyalevil removed their assignment Feb 28, 2023
@anshgoyalevil
Copy link
Contributor Author

@palisadoes
I have unassigned myself from this issue.
This is a good first issue, so want new contributors to get into it. It would give them a thorough understanding of the project.

@KrutikaBhatt
Copy link
Contributor

Can I work on this?

@xoldd
Copy link
Contributor

xoldd commented Mar 2, 2023

@KrutikaBhatt assigned you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants