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

How to get Error Code or Message? #67

Closed
voyage11 opened this issue Aug 29, 2018 · 4 comments
Closed

How to get Error Code or Message? #67

voyage11 opened this issue Aug 29, 2018 · 4 comments

Comments

@voyage11
Copy link

Hi,
I have been searching for a way to extract the code and message out from the error.

For example:-
Error: Error(code: -32000, message: "insufficient funds for gas * price + value")

How can I get the Code and the Message?

@koraykoska
Copy link
Member

If you have an instance of error you could do something like that:

if let error = error as? RPCResponse<EthereumData>.Error {
    print(error.code)
    print(error.message)
}

@koraykoska
Copy link
Member

Having to provide the generic type for RPCResponse on your own is really not great. I think we should change the Error to a non-subtype.

@koraykoska
Copy link
Member

Btw, my example is only possible with version 0.3.1 which was released just today...

@voyage11
Copy link
Author

voyage11 commented Sep 2, 2018

I tested. It worked great! Thanks @Ybrin !

@voyage11 voyage11 closed this as completed Sep 2, 2018
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

No branches or pull requests

2 participants