fix(plugin): a try catch for webscoket send
This commit is contained in:
		
							parent
							
								
									5b2cb407c7
								
							
						
					
					
						commit
						0dec0015a5
					
				@ -132,13 +132,18 @@ async def websocket_handler(request):
 | 
				
			|||||||
    return ws
 | 
					    return ws
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def send(event, data, sid=None):
 | 
					async def send(event, data, sid=None):
 | 
				
			||||||
    if sid:
 | 
					    try:
 | 
				
			||||||
        ws = sockets.get(sid)
 | 
					        if sid:
 | 
				
			||||||
        if ws:
 | 
					            ws = sockets.get(sid)
 | 
				
			||||||
            await ws.send_json({ 'event': event, 'data': data })
 | 
					            if ws and not ws.closed:  # Check if the WebSocket connection is open and not closing
 | 
				
			||||||
    else:
 | 
					                await ws.send_json({ 'event': event, 'data': data })
 | 
				
			||||||
        for ws in sockets.values():
 | 
					        else:
 | 
				
			||||||
            await ws.send_json({ 'event': event, 'data': data })
 | 
					            for ws in sockets.values():
 | 
				
			||||||
 | 
					                if not ws.closed:  # Check if the WebSocket connection is open and not closing
 | 
				
			||||||
 | 
					                    await ws.send_json({ 'event': event, 'data': data })
 | 
				
			||||||
 | 
					    except Exception as e:
 | 
				
			||||||
 | 
					        print(f"Exception: {e}")
 | 
				
			||||||
 | 
					        traceback.print_exc()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
logging.basicConfig(level=logging.INFO)
 | 
					logging.basicConfig(level=logging.INFO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user