Skip to content

RPC Service: Improve error handling for HTTP status codes #5844

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

Open
cryptodev-2s opened this issue May 21, 2025 · 1 comment · Fixed by #5843 · May be fixed by #5923
Open

RPC Service: Improve error handling for HTTP status codes #5844

cryptodev-2s opened this issue May 21, 2025 · 1 comment · Fixed by #5843 · May be fixed by #5923

Comments

@cryptodev-2s
Copy link
Contributor

cryptodev-2s commented May 21, 2025

Problem

The RPC service currently has inconsistent error handling for different HTTP status codes. Some status codes are handled with generic errors, making it difficult to:

  • Debug issues
  • Handle specific error cases in the application
  • Provide meaningful error messages to users

Proposed Solution

Improve error handling by implementing specific error types for different HTTP status codes:

  • 401: Unauthorized error
  • 402/404/5xx: Resource unavailable error
  • 405/501: Method not found error
  • 429: Rate limiting error
  • Other 4xx: Invalid request error
  • Invalid JSON: Parse error

Benefits

  • More predictable error handling
  • Better debugging capabilities
  • Clearer error messages for users
  • Consistent error data structure
  • Improved test coverage and documentation

Testing

  • Verify all HTTP status codes are handled correctly
  • Ensure error messages are consistent
  • Check that error data includes necessary information
  • Run existing test suite to confirm no regressions
@cryptodev-2s cryptodev-2s self-assigned this May 21, 2025
cryptodev-2s added a commit that referenced this issue May 23, 2025
## Explanation

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

Improves error handling in the RPC service by making it more specific
and consistent. The changes include:

- Clarifies error handling for different HTTP status codes:
  - 401: Unauthorized error
  - 402/404/5xx: Resource unavailable error
  - 405/501: Method not found error
  - 429: Rate limiting error
  - Other 4xx: Invalid request error
  - Invalid JSON: Parse error

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

Fixes #5844

## Changelog

<!--
THIS SECTION IS NO LONGER NEEDED.

The process for updating changelogs has changed. Please consult the
"Updating changelogs" section of the Contributing doc for more.
-->

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@mcmire
Copy link
Contributor

mcmire commented May 30, 2025

We reverted the above PR as we need to verify with the Wallet API team that these changes don't cause any issues with dapps before merging it.

@mcmire mcmire reopened this May 30, 2025
@cryptodev-2s cryptodev-2s linked a pull request Jun 5, 2025 that will close this issue
4 tasks
@mcmire mcmire self-assigned this Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants