rpc/client: only return the Result from calls, handle Error internally

Adjust structures accordingly and throw away most of them, they're useless.
This commit is contained in:
Roman Khimov 2020-02-20 21:08:22 +03:00
parent 28a26d2cae
commit 3fa9de764b
5 changed files with 52 additions and 72 deletions

View file

@ -590,6 +590,14 @@ func (s *Server) WriteErrorResponse(r *request.In, w http.ResponseWriter, err er
// WriteResponse encodes the response and writes it to the ResponseWriter.
func (s *Server) WriteResponse(r *request.In, w http.ResponseWriter, result interface{}) {
resJSON, err := json.Marshal(result)
if err != nil {
s.log.Error("Error encountered while encoding response",
zap.String("err", err.Error()),
zap.String("method", r.Method))
return
}
resp := response.Raw{
HeaderAndError: response.HeaderAndError{
Header: response.Header{
@ -597,7 +605,7 @@ func (s *Server) WriteResponse(r *request.In, w http.ResponseWriter, result inte
ID: r.RawID,
},
},
Result: result,
Result: resJSON,
}
s.writeServerResponse(r, w, resp)