Update fetch middleware to preserve original error data #349
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.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 wholebody.error
has the advantage ofparseOpts
ingetJsonRpcError
handling the case in which ifbody.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.