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

Refactor Remove AcceptedErrorCodes from MirrorNodeClient - GET_ACCOUNTS_BY_ID_ENDPOINT #1649

Closed

Conversation

AlfredoG87
Copy link
Collaborator

@AlfredoG87 AlfredoG87 commented Aug 18, 2023

Description:
Refactor methods that use mirror node endpoint GET_ACCOUNTS_BY_ID_ENDPOINT: getAccount, getAccountLatestEthereumTransactionsByTimestamp, getAccountPageLimit to stop accepting error codes 400 and 404, but instead to throw the error and moved the handling of the error to be specific of those methods and not as a general handler for all errors on the mirror node requests

Related issue(s)

Addresses #1276

Notes for reviewer:
This replaces this other PR

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@AlfredoG87 AlfredoG87 marked this pull request as ready for review August 18, 2023 19:59
@AlfredoG87 AlfredoG87 self-assigned this Aug 18, 2023
@AlfredoG87 AlfredoG87 added enhancement New feature or request P2 labels Aug 18, 2023
@AlfredoG87 AlfredoG87 added this to the 0.30.0 milestone Aug 18, 2023
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Looking good.
Not sure why we need the overloads vs just adopting the logic and allowing callers to manage the null

* @param {string} idOrAliasOrEvmAddress commonly an evm address
* @param {string} requestIdPrefix optional request id prefix
*/
public async getAccountOrNull(idOrAliasOrEvmAddress: string, requestIdPrefix?: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: why the OrNull method overload?
Should services calling this handle the null?

Copy link
Collaborator Author

@AlfredoG87 AlfredoG87 Aug 18, 2023

Choose a reason for hiding this comment

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

Yes, methods handle the null, this overload is to return null whenever a 404 exception is thrown.

Handling the Exception on each service was my original approach, but then realized that this methods are used by many different services (eth.ts, precheck.ts and relay.ts) and that I had to handle basically the same logic in all 3 services, so I needed to share the handleAccountNotFound logic in all 3 classes, so Instead of copy pasting (or creating a new helper class for the mirrorNodeClient), and then modify all the reference where the logic already expects a null to add a try catch block, did not seem like progress or improvement to the code.

The difference between this approach and current one of having a collection of acceptedErrorCodes is that there you don't have the option to get exceptions once the status is added to the collection, and it applies to all the different methods that might use the same endpoint, so there is no intentionality, and handles the same, any code such as 400 that in these cases, it should throw errors.

return this.get(`${MirrorNodeClient.GET_ACCOUNTS_BY_ID_ENDPOINT}${idOrAliasOrEvmAddress}?limit=${constants.MIRROR_NODE_QUERY_LIMIT}`,
MirrorNodeClient.GET_ACCOUNTS_BY_ID_ENDPOINT,
requestIdPrefix);
public async getAccountPageLimitOrNull(idOrAliasOrEvmAddress: string, requestIdPrefix?: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: why the OrNull method overload?
Should services calling this handle the null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above

…NDPOINT`: getAccount, getAccountLatestEthereumTransactionsByTimestamp, getAccountPageLimit to stop accepting error codes 400 and 404, but instead to throw the error and moved the handling of the error to be specific of those methods and not as a general handler for all errors on the mirror node requests

Signed-off-by: Alfredo Gutierrez <[email protected]>
@AlfredoG87 AlfredoG87 force-pushed the 1276-refactor-GetAccountsById-remove-accepted-code branch from 81f36cf to 53b8cd0 Compare August 18, 2023 21:48
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 86.56% and project coverage change: +0.17% 🎉

Comparison is base (6724e2a) 77.29% compared to head (d1c3c8f) 77.46%.
Report is 3 commits behind head on main.

❗ Current head d1c3c8f differs from pull request most recent head 53b8cd0. Consider uploading reports for the commit 53b8cd0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1649      +/-   ##
==========================================
+ Coverage   77.29%   77.46%   +0.17%     
==========================================
  Files          36       36              
  Lines        2739     2778      +39     
  Branches      554      565      +11     
==========================================
+ Hits         2117     2152      +35     
- Misses        447      449       +2     
- Partials      175      177       +2     
Files Changed Coverage Δ
packages/relay/src/lib/relay.ts 68.62% <0.00%> (-2.81%) ⬇️
packages/server/src/validator/methods.ts 100.00% <ø> (ø)
packages/server/src/validator/utils.ts 89.47% <88.88%> (+1.37%) ⬆️
packages/relay/src/lib/clients/mirrorNodeClient.ts 88.45% <94.73%> (+0.18%) ⬆️
packages/relay/src/lib/eth.ts 85.39% <95.83%> (+0.14%) ⬆️
packages/relay/src/lib/precheck.ts 58.53% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AlfredoG87
Copy link
Collaborator Author

Closed in favor of #1651

@AlfredoG87 AlfredoG87 closed this Aug 18, 2023
@AlfredoG87 AlfredoG87 deleted the 1276-refactor-GetAccountsById-remove-accepted-code branch August 23, 2023 15:57
@ebadiere ebadiere modified the milestones: 0.30.0, 0.31.1 Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants