mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
rpc/client: look into data first, then HTTP error code
In case of error our own server responds with an HTTP error and proper JSON-RPC error in the body, so look there first as it has more specific data.
This commit is contained in:
parent
877b987ecf
commit
28a26d2cae
1 changed files with 6 additions and 3 deletions
|
@ -203,11 +203,14 @@ func (c *Client) performRequest(method string, p request.RawParams, v interface{
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("remote responded with a non 200 response: %d", resp.StatusCode)
|
||||
// The node might send us proper JSON anyway, so look there first and if
|
||||
// it parses, then it has more relevant data than HTTP error code.
|
||||
err = json.NewDecoder(resp.Body).Decode(v)
|
||||
if resp.StatusCode != http.StatusOK && err != nil {
|
||||
err = fmt.Errorf("HTTP %d/%s", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
}
|
||||
|
||||
return json.NewDecoder(resp.Body).Decode(v)
|
||||
return err
|
||||
}
|
||||
|
||||
// Ping attempts to create a connection to the endpoint.
|
||||
|
|
Loading…
Reference in a new issue