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

Handle RPC Error properly #59

Open
cubismic opened this issue Jan 2, 2020 · 0 comments
Open

Handle RPC Error properly #59

cubismic opened this issue Jan 2, 2020 · 0 comments

Comments

@cubismic
Copy link
Member

cubismic commented Jan 2, 2020

Currently, if RPC error occurs, the error message just gives
unexpected end of JSON input
Because the error format provided by the rpc server is as follows:

{
  code: -32032,
  message: 'Not Enough Balance',
  data: 'InsufficientBalance { address: Address(~~), balance: ~, cost: ~ }'
}

unexpected end of JSON input comes from line 75.
(body has the error message in byte slice)

resp, err := client.httpClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
body, readerr := ioutil.ReadAll(resp.Body)
if readerr != nil {
return readerr
}
var outerResult Result
if err := json.Unmarshal(body, &outerResult); err != nil {
return err
}

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

1 participant