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

feat: added support for JSON RPC Error object #635

Conversation

JeneaVranceanu
Copy link
Collaborator

If there is an error during the execution of a JSON RPC request we may receive a response containing the error information.
See JSON Error object specification: https://www.jsonrpc.org/specification#error_object

Here is an example of an error before:

Screenshot 2022-10-09 at 10 26 03

And here is the same error after error object parsing was added:

Screenshot 2022-10-09 at 10 26 38

@JeneaVranceanu
Copy link
Collaborator Author

Consider extending error codes to support this list: https://docs.infura.io/infura/networks/ethereum/json-rpc-methods

/// This bit of code is purposed to work with literal types that comes in ``Response`` in hexString type.
/// Currently it's just `Data` and any kind of Integers `(U)Int`, `Big(U)Int`.
if Result.self == Data.self || Result.self == UInt.self || Result.self == Int.self || Result.self == BigInt.self || Result.self == BigUInt.self {
guard let LiteralType = Result.self as? LiteralInitiableFromString.Type else { throw Web3Error.typeError }
if let LiteralType = Result.self as? LiteralInitiableFromString.Type {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, that's nice 🙂
Like now we can made this protocol expandable on client side either.

@yaroslavyaroslav yaroslavyaroslav merged commit 7dee353 into web3swift-team:develop Oct 9, 2022
@JeneaVranceanu JeneaVranceanu deleted the fix/parsing-json-rpc-errors branch October 10, 2022 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants