mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
CR: export error string generation to a function
This commit is contained in:
parent
9440bc5d72
commit
98fa3855bd
@ -174,7 +174,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
AllowPorts: make(map[int]struct{}),
|
AllowPorts: make(map[int]struct{}),
|
||||||
MaxPoolCount: 5,
|
MaxPoolCount: 5,
|
||||||
MaxPortsPerClient: 0,
|
MaxPortsPerClient: 0,
|
||||||
TlsOnly: false,
|
TlsOnly: false,
|
||||||
HeartBeatTimeout: 90,
|
HeartBeatTimeout: 90,
|
||||||
UserConnTimeout: 10,
|
UserConnTimeout: 10,
|
||||||
Custom404Page: "",
|
Custom404Page: "",
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/fatedier/frp/server/controller"
|
"github.com/fatedier/frp/server/controller"
|
||||||
"github.com/fatedier/frp/server/proxy"
|
"github.com/fatedier/frp/server/proxy"
|
||||||
"github.com/fatedier/frp/server/stats"
|
"github.com/fatedier/frp/server/stats"
|
||||||
|
"github.com/fatedier/frp/utils/util"
|
||||||
"github.com/fatedier/frp/utils/version"
|
"github.com/fatedier/frp/utils/version"
|
||||||
"github.com/fatedier/frp/utils/xlog"
|
"github.com/fatedier/frp/utils/xlog"
|
||||||
|
|
||||||
@ -438,12 +439,8 @@ func (ctl *Control) manager() {
|
|||||||
ProxyName: m.ProxyName,
|
ProxyName: m.ProxyName,
|
||||||
}
|
}
|
||||||
if err != nil {
|
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)
|
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 {
|
} else {
|
||||||
resp.RemoteAddr = remoteAddr
|
resp.RemoteAddr = remoteAddr
|
||||||
xl.Info("new proxy [%s] success", m.ProxyName)
|
xl.Info("new proxy [%s] success", m.ProxyName)
|
||||||
|
@ -320,13 +320,9 @@ func (svr *Service) HandleListener(l net.Listener) {
|
|||||||
// Otherwise send success message in control's work goroutine.
|
// Otherwise send success message in control's work goroutine.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("register control error: %v", err)
|
xl.Warn("register control error: %v", err)
|
||||||
errStr := "register control error"
|
|
||||||
if svr.cfg.DetailedErrorsToClient {
|
|
||||||
errStr = err.Error()
|
|
||||||
}
|
|
||||||
msg.WriteMsg(conn, &msg.LoginResp{
|
msg.WriteMsg(conn, &msg.LoginResp{
|
||||||
Version: version.Full(),
|
Version: version.Full(),
|
||||||
Error: errStr,
|
Error: util.GenerateResponseErrorString("register control error", err, svr.cfg.DetailedErrorsToClient),
|
||||||
})
|
})
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
@ -335,13 +331,9 @@ func (svr *Service) HandleListener(l net.Listener) {
|
|||||||
case *msg.NewVisitorConn:
|
case *msg.NewVisitorConn:
|
||||||
if err = svr.RegisterVisitorConn(conn, m); err != nil {
|
if err = svr.RegisterVisitorConn(conn, m); err != nil {
|
||||||
xl.Warn("register visitor conn error: %v", err)
|
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{
|
msg.WriteMsg(conn, &msg.NewVisitorConnResp{
|
||||||
ProxyName: m.ProxyName,
|
ProxyName: m.ProxyName,
|
||||||
Error: errStr,
|
Error: util.GenerateResponseErrorString("register visitor conn error", err, svr.cfg.DetailedErrorsToClient),
|
||||||
})
|
})
|
||||||
conn.Close()
|
conn.Close()
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,3 +101,11 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateResponseErrorString(summary string, err error, detailed bool) string {
|
||||||
|
if detailed {
|
||||||
|
return err.Error()
|
||||||
|
} else {
|
||||||
|
return summary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user