fix ErrorConnection event format

This commit is contained in:
Maxim Merzhanov authored and Maxim committed 2019-10-31 17:01:11 +03:00
1 parent 74b32e064e
commit a958874731
4 files changed
+15 -6

No files matched your search

+3 -2
View File
@@ -43,10 +43,11 @@ func (c *SocketLeaderClient) SendDeclaration(backend structure.BackendDeclaratio
func (c *SocketLeaderClient) Dial(timeout time.Duration) error {
backOff := backoff.NewExponentialBackOff()
backOff.MaxElapsedTime = timeout
bf := backoff.WithContext(backOff, c.globalCtx)
dial := func() error {
return c.client.Dial(context.Background(), c.url)
return c.client.Dial(c.globalCtx, c.url)
}
return backoff.Retry(dial, backOff)
return backoff.Retry(dial, bf)
}
func (c *SocketLeaderClient) Close() {
+2 -2
View File
@@ -67,8 +67,8 @@ func (ds *discoveryService) BroadcastModuleAddresses(moduleName string, mesh sta
defer ds.lock.RUnlock()
event := utils.ModuleConnected(moduleName)
addressList := mesh.GetModuleAddresses(moduleName)
go func(moduleName, event string, addressList []structure.AddressConfiguration) {
err := ds.broadcastAddrList(moduleName, event, addressList)
go func(room, event string, addressList []structure.AddressConfiguration) {
err := ds.broadcastAddrList(room, event, addressList)
if err != nil {
log.Errorf(codes.DiscoveryServiceSendModulesError, "broadcast module connected %v", err)
}
+8
View File
@@ -34,3 +34,11 @@ func SyncApplyCommand(command []byte, commandName string) (interface{}, error) {
}
return applyLogResponse.Result, nil
}
func FormatErrorConnection(err error) []byte {
errMap := map[string]interface{}{
"error": err,
}
data, _ := json.Marshal(errMap)
return data
}
+2 -2
View File
@@ -47,7 +47,7 @@ func (h *socketEventHandler) handleConnect(conn etp.Conn) {
moduleName, err := Parameters(conn)
log.Debugf(0, "handleConnect: %s", moduleName) // REMOVE
if err != nil {
EmitConn(conn, utils.ErrorConnection, []byte(err.Error()))
EmitConn(conn, utils.ErrorConnection, FormatErrorConnection(err))
_ = conn.Close()
return
}
@@ -62,7 +62,7 @@ func (h *socketEventHandler) handleConnect(conn etp.Conn) {
command := cluster.PrepareModuleConnectedCommand(module)
_, err = SyncApplyCommand(command, "ModuleConnectedCommand")
if err != nil && !isClusterNode {
EmitConn(conn, utils.ErrorConnection, []byte(err.Error()))
EmitConn(conn, utils.ErrorConnection, FormatErrorConnection(err))
_ = conn.Close()
return
}