near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.31k stars 615 forks source link

feat: improved RPC's response error handling with HTTP status codes #11806

Closed frolvanya closed 1 month ago

frolvanya commented 2 months ago

This PR updates the RPC handler to return appropriate HTTP errors for specific RPC issues, improving error visibility for operators

closes #11792

frolvanya commented 2 months ago

On the one hand, this makes sense. However, If we will send a structure other than Result, then we will have to rewrite jsonrpc tests. Is it worth it? image

Also, we need to make Version struct pub, it's not necessarily a bad idea, but it's definetely a small overhead image

And process function in the very end will have these ugly raw response builders: image

frolvanya commented 2 months ago

@shreyan-gupta Sorry, it took a bit longer than expected, but I removed Result from process function

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 51.51515% with 16 lines in your changes missing coverage. Please review.

Project coverage is 71.75%. Comparing base (d7e1232) to head (f1b8323). Report is 11 commits behind head on master.

Files Patch % Lines
chain/jsonrpc/src/lib.rs 51.51% 16 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #11806 +/- ## ========================================== + Coverage 71.74% 71.75% +0.01% ========================================== Files 796 796 Lines 163004 163183 +179 Branches 163004 163183 +179 ========================================== + Hits 116940 117095 +155 - Misses 41003 41038 +35 + Partials 5061 5050 -11 ``` | [Flag](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | Coverage Δ | | |---|---|---| | [backward-compatibility](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.23% <0.00%> (-0.01%)` | :arrow_down: | | [db-migration](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.23% <0.00%> (-0.01%)` | :arrow_down: | | [genesis-check](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.35% <0.00%> (-0.01%)` | :arrow_down: | | [integration-tests](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `37.83% <33.33%> (+<0.01%)` | :arrow_up: | | [linux](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.37% <51.51%> (+0.12%)` | :arrow_up: | | [linux-nightly](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.35% <51.51%> (+0.01%)` | :arrow_up: | | [macos](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `54.61% <51.51%> (+1.66%)` | :arrow_up: | | [pytests](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.62% <0.00%> (+0.03%)` | :arrow_up: | | [sanity-checks](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.42% <0.00%> (+0.03%)` | :arrow_up: | | [unittests](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `66.21% <51.51%> (+0.02%)` | :arrow_up: | | [upgradability](https://app.codecov.io/gh/near/nearcore/pull/11806/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.28% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

frolvanya commented 1 month ago

@race-of-sloths please, include my PR in the Race

race-of-sloths commented 1 month ago

@frolvanya Thank you for your contribution! Your pull request is now a part of the Race of Sloths!

[

<source media="(prefers-color-scheme: light)" srcset="https://badge.race-of-sloths.com/frolvanya?type=bot&theme=light">
<img alt="Shows profile picture for the author of the PR" src="https://badge.race-of-sloths.com/frolvanya?type=bot&theme=white">

](https://race-of-sloths.com/profile/frolvanya)

Current status: executed @frolvanya check out your results on the [Race of Sloths Leaderboard!](https://race-of-sloths.com/leaderboard) and in the [profile](https://race-of-sloths.com/profile/frolvanya)
What is the Race of Sloths

Race of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors: - Tag @race-of-sloths inside your pull requests - Wait for the maintainer to review and score your pull request - Check out your position in the [Leaderboard](https://race-of-sloths.com/leaderboard) - Keep weekly and monthly streaks to reach higher positions - Boast your contributions with a dynamic picture of your [Profile](https://race-of-sloths.com/profile/frolvanya) For maintainers: - Score pull requests that participate in the Race of Sloths - Engage contributors with fair scoring and fast responses so they keep their streaks - Promote the Race to the point where the Race starts promoting you - Grow the community of your contributors Feel free to check [our website](https://race-of-sloths.com) for additional details!

Bot commands - For contributors - **Include a PR:** `@race-of-sloths include` to enter the Race with your PR - For maintainers: - **Assign points:** `@race-of-sloths score [1/2/3/5/8/13]` to award points based on your assessment. - **Reject this PR:** `@race-of-sloths exclude` to send this PR back to the drawing board. - **Exclude repo:** `@race-of-sloths pause` to stop bot activity in this repo until `@race-of-sloths unpause` command is called
race-of-sloths commented 1 month ago

🔄 The PR has been merged.

[!IMPORTANT] This pull request is a part of the Race of Sloths and has not been scored yet. Scoring will close in 24 hours! 🕰️

race-of-sloths commented 1 month ago

✅ PR is finalized!

Your contribution is much appreciated with a final score of 0! You have received 0 Sloth points for this contribution