diff --git a/models/config/server_common.go b/models/config/server_common.go index 6ad2688..20e92f9 100644 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -174,7 +174,7 @@ func GetDefaultServerConf() ServerCommonConf { AllowPorts: make(map[int]struct{}), MaxPoolCount: 5, MaxPortsPerClient: 0, - TlsOnly: false, + TlsOnly: false, HeartBeatTimeout: 90, UserConnTimeout: 10, Custom404Page: "", diff --git a/server/control.go b/server/control.go index bb06ccf..4b9227a 100644 --- a/server/control.go +++ b/server/control.go @@ -31,6 +31,7 @@ import ( "github.com/fatedier/frp/server/controller" "github.com/fatedier/frp/server/proxy" "github.com/fatedier/frp/server/stats" + "github.com/fatedier/frp/utils/util" "github.com/fatedier/frp/utils/version" "github.com/fatedier/frp/utils/xlog" @@ -438,12 +439,8 @@ func (ctl *Control) manager() { ProxyName: m.ProxyName, } if err != nil { - if ctl.serverCfg.DetailedErrorsToClient { - resp.Error = err.Error() - } else { - resp.Error = fmt.Sprintf("new proxy [%s] error", m.ProxyName) - } xl.Warn("new proxy [%s] error: %v", m.ProxyName, err) + resp.Error = util.GenerateResponseErrorString(fmt.Sprintf("new proxy [%s] error", m.ProxyName), err, ctl.serverCfg.DetailedErrorsToClient) } else { resp.RemoteAddr = remoteAddr xl.Info("new proxy [%s] success", m.ProxyName) diff --git a/server/service.go b/server/service.go index 50ebe0f..1ad7e28 100644 --- a/server/service.go +++ b/server/service.go @@ -320,13 +320,9 @@ func (svr *Service) HandleListener(l net.Listener) { // Otherwise send success message in control's work goroutine. if err != nil { xl.Warn("register control error: %v", err) - errStr := "register control error" - if svr.cfg.DetailedErrorsToClient { - errStr = err.Error() - } msg.WriteMsg(conn, &msg.LoginResp{ Version: version.Full(), - Error: errStr, + Error: util.GenerateResponseErrorString("register control error", err, svr.cfg.DetailedErrorsToClient), }) conn.Close() } @@ -335,13 +331,9 @@ func (svr *Service) HandleListener(l net.Listener) { case *msg.NewVisitorConn: if err = svr.RegisterVisitorConn(conn, m); err != nil { xl.Warn("register visitor conn error: %v", err) - errStr := "register visitor conn error" - if svr.cfg.DetailedErrorsToClient { - errStr = err.Error() - } msg.WriteMsg(conn, &msg.NewVisitorConnResp{ ProxyName: m.ProxyName, - Error: errStr, + Error: util.GenerateResponseErrorString("register visitor conn error", err, svr.cfg.DetailedErrorsToClient), }) conn.Close() } else { diff --git a/utils/util/util.go b/utils/util/util.go index 7ea4e83..5b30d54 100644 --- a/utils/util/util.go +++ b/utils/util/util.go @@ -101,3 +101,11 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) { } return } + +func GenerateResponseErrorString(summary string, err error, detailed bool) string { + if detailed { + return err.Error() + } else { + return summary + } +}