etcdserver/api/v2http/client.go
func writeKeyError(lg *zap.Logger, w http.ResponseWriter, err error) {
	if err == nil {
		return
	}
	switch e := err.(type) {
	case *v2error.Error:
		e.WriteTo(w)
	default:
		switch err {
		case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost:
			if lg != nil {
				lg.Warn(
					"v2 response error",
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeError(err)
			}
		default:
			if lg != nil {
				lg.Warn(
					"unexpected v2 response error",
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeErrorf("got unexpected response error (%v)", err)
			}
		}
		ee := v2error.NewError(v2error.EcodeRaftInternal, err.Error(), 0)
		ee.WriteTo(w)
	}
}
func writeKeyError(lg *zap.Logger, w http.ResponseWriter, err error) {
	if err == nil {
		return
	}
	switch e := err.(type) {
	case *v2error.Error:
		e.WriteTo(w)
	default:
		switch err {
		case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost:
			if lg != nil {
				lg.Warn(
					"v2 response error",
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeError(err)
			}
		default:
			if lg != nil {
				lg.Warn(
					"unexpected v2 response error",
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeErrorf("got unexpected response error (%v)", err)
			}
		}
		ee := v2error.NewError(v2error.EcodeRaftInternal, err.Error(), 0)
		ee.WriteTo(w)
	}
}
// writeKeyError logs and writes the given Error to the ResponseWriter.
// If Error is not an etcdErr, the error will be converted to an etcd error.