etcdserver/api/etcdhttp/base.go
func WriteError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) {
	if err == nil {
		return
	}
	switch e := err.(type) {
	case *v2error.Error:
		e.WriteTo(w)

	case *httptypes.HTTPError:
		if et := e.WriteTo(w); et != nil {
			if lg != nil {
				lg.Debug(
					"failed to write v2 HTTP error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", e.Error()),
					zap.Error(et),
				)
			} else {
				plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr)
			}
		}

	default:
		switch err {
		case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost, etcdserver.ErrNotEnoughStartedMembers,
			etcdserver.ErrUnhealthy:
			if lg != nil {
				lg.Warn(
					"v2 response error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeError(err)
			}

		default:
			if lg != nil {
				lg.Warn(
					"unexpected v2 response error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeErrorf("got unexpected response error (%v)", err)
			}
		}

		herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error")
		if et := herr.WriteTo(w); et != nil {
			if lg != nil {
				lg.Debug(
					"failed to write v2 HTTP error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
					zap.Error(et),
				)
			} else {
				plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr)
			}
		}
	}
}
func WriteError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) {
	if err == nil {
		return
	}
	switch e := err.(type) {
	case *v2error.Error:
		e.WriteTo(w)

	case *httptypes.HTTPError:
		if et := e.WriteTo(w); et != nil {
			if lg != nil {
				lg.Debug(
					"failed to write v2 HTTP error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", e.Error()),
					zap.Error(et),
				)
			} else {
				plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr)
			}
		}

	default:
		switch err {
		case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost, etcdserver.ErrNotEnoughStartedMembers,
			etcdserver.ErrUnhealthy:
			if lg != nil {
				lg.Warn(
					"v2 response error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeError(err)
			}

		default:
			if lg != nil {
				lg.Warn(
					"unexpected v2 response error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
				)
			} else {
				mlog.MergeErrorf("got unexpected response error (%v)", err)
			}
		}

		herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error")
		if et := herr.WriteTo(w); et != nil {
			if lg != nil {
				lg.Debug(
					"failed to write v2 HTTP error",
					zap.String("remote-addr", r.RemoteAddr),
					zap.String("internal-server-error", err.Error()),
					zap.Error(et),
				)
			} else {
				plog.Debugf("error writing HTTPError (%v) to %s", et, r.RemoteAddr)
			}
		}
	}
}
func WriteError ( lg * zap . Logger , w http . ResponseWriter , r * http . Request , err error ) { if err == nil { return } switch e := err . ( type ) { case * v2error . Error : e . WriteTo ( w ) case * httptypes . HTTPError : if et := e . WriteTo ( w ) ; et != nil { if lg != nil { lg . Debug ( " " , zap . String ( " " , r . RemoteAddr ) , zap . String ( " " , e . Error ( ) ) , zap . Error ( et ) , ) } else { plog . Debugf ( " " , et , r . RemoteAddr ) } } default : switch err { case etcdserver . ErrTimeoutDueToLeaderFail , etcdserver . ErrTimeoutDueToConnectionLost , etcdserver . ErrNotEnoughStartedMembers , etcdserver . ErrUnhealthy : if lg != nil { lg . Warn ( " " , zap . String ( " " , r . RemoteAddr ) , zap . String ( " " , err . Error ( ) ) , ) } else { mlog . MergeError ( err ) } default : if lg != nil { lg . Warn ( " " , zap . String ( " " , r . RemoteAddr ) , zap . String ( " " , err . Error ( ) ) , ) } else { mlog . MergeErrorf ( " " , err ) } } herr := httptypes . NewHTTPError ( http . StatusInternalServerError , " " ) if et := herr . WriteTo ( w ) ; et != nil { if lg != nil { lg . Debug ( " " , zap . String ( " " , r . RemoteAddr ) , zap . String ( " " , err . Error ( ) ) , zap . Error ( et ) , ) } else { plog . Debugf ( " " , et , r . RemoteAddr ) } } } }
// WriteError logs and writes the given Error to the ResponseWriter
// If Error is an etcdErr, it is rendered to the ResponseWriter
// Otherwise, it is assumed to be a StatusInternalServerError
WriteError logs and writes the given Error to the ResponseWriter If Error is an etcdErr it is rendered to the ResponseWriter Otherwise it is assumed to be a StatusInternalServerError