You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 16, 2025. It is now read-only.
Recently the rpc-errors package had been updated to preserve the original RPC error message (MetaMask/rpc-errors#160). However, the fetch middleware in this package has been preventing this as it has not been forwarding the body.error.message string from the response, instead rewriting all errors with the default 'Internal JSON-RPC error.'. This PR addresses that.
The data could also be passed explicitly as rpcErrors.internal({ message: body.error.message, data: body.error.data }) but the approach of passing the whole body.error has the advantage of parseOpts in getJsonRpcError handling the case in which if body.error is not an object but a string.
I wanted to add tests to cover this, but the only way I see this being done is by exporting the parseResponse method. Let me know if this is something you'd like covered.
I wanted to add tests to cover this, but the only way I see this being done is by exporting the parseResponse method. Let me know if this is something you'd like covered.
Rather than unit-testing the internal behavior of this this otherwise unexported function, seems more appropriate to extend fetch.test.ts with tests that instantiate a fetch-middleware using createFetchMiddleware, then testing for that errors result in the expected (serializable?) result? Some similar tests already exist for retryOnEmptyMiddleware (e.g. #154, #254).
but the approach of passing the whole body.error has the advantage of parseOpts in getJsonRpcError handling the case in which if body.error is not an object but a string.
In particular I guess it would benefit from a regression test covering the eventuality of input error objects being cyclical, in order to cover for situations like:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recently the rpc-errors package had been updated to preserve the original RPC error message (MetaMask/rpc-errors#160). However, the fetch middleware in this package has been preventing this as it has not been forwarding the
body.error.messagestring from the response, instead rewriting all errors with the default 'Internal JSON-RPC error.'. This PR addresses that.The data could also be passed explicitly as
rpcErrors.internal({ message: body.error.message, data: body.error.data })but the approach of passing the wholebody.errorhas the advantage ofparseOptsingetJsonRpcErrorhandling the case in which ifbody.erroris not an object but a string.I wanted to add tests to cover this, but the only way I see this being done is by exporting the
parseResponsemethod. Let me know if this is something you'd like covered.