Skip to content

Commit

Permalink
rpc error optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
dydysy committed Mar 20, 2018
1 parent 59ff5a7 commit 87760aa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions rpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,17 @@ func (c *rpcClient) call(method string, params interface{}) (rr rpcResponse, err
return
}

var rErr rpcError
if resp.StatusCode != 200 {
err = errors.New("HTTP error: " + resp.Status)
if json.Unmarshal(data, &rErr) != nil {
return
}
}
if errUnmarshal := json.Unmarshal(data, &rr); errUnmarshal != nil {
err = errUnmarshal

err = json.Unmarshal(data, &rr)
if err != nil {
return
}
if rErr.Message != "" { //当有rpc error 发生的时候,把error结果也返回
rr.Err = rErr
err = errors.New(fmt.Sprintf("%v : %v", rr.Err.Code, rr.Err.Message))

if resp.StatusCode != 200 {
err = errors.New("HTTP error: "+resp.Status + " error message: " + rr.Err.Message)
}
return
}

0 comments on commit 87760aa

Please sign in to comment.