rpc: print error data field

This commit is contained in:
rjl493456442
2020-06-03 13:50:48 +08:00
committed by Péter Szilágyi
parent 5048fd1028
commit c7765c0abb
2 changed files with 12 additions and 2 deletions

View File

@ -296,10 +296,16 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
return nil
case msg.isCall():
resp := h.handleCall(ctx, msg)
var ctx []interface{}
ctx = append(ctx, "reqid", idForLog{msg.ID}, "t", time.Since(start))
if resp.Error != nil {
h.log.Warn("Served "+msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start), "err", resp.Error.Message)
ctx = append(ctx, "err", resp.Error.Message)
if resp.Error.Data != nil {
ctx = append(ctx, "errdata", resp.Error.Data)
}
h.log.Warn("Served "+msg.Method, ctx...)
} else {
h.log.Debug("Served "+msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start))
h.log.Debug("Served "+msg.Method, ctx...)
}
return resp
case msg.hasValidID():

View File

@ -139,6 +139,10 @@ func (err *jsonError) ErrorCode() int {
return err.Code
}
func (err *jsonError) ErrorData() interface{} {
return err.Data
}
// Conn is a subset of the methods of net.Conn which are sufficient for ServerCodec.
type Conn interface {
io.ReadWriteCloser