forked from TrueCloudLab/neoneo-go
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()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
// The node might send us proper JSON anyway, so look there first and if
|
||||||
return fmt.Errorf("remote responded with a non 200 response: %d", resp.StatusCode)
|
// 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.
|
// Ping attempts to create a connection to the endpoint.
|
||||||
|
|
Loading…
Reference in a new issue