From 1b92300445e8a0d76a6778c4e2802b6d2ff631a5 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 14 Jul 2015 23:38:51 +0800 Subject: Handle when OT throw Error, will log it then disconnect socket client --- lib/ot/editor-socketio-server.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/ot') diff --git a/lib/ot/editor-socketio-server.js b/lib/ot/editor-socketio-server.js index aae156fc..ade8fc52 100755 --- a/lib/ot/editor-socketio-server.js +++ b/lib/ot/editor-socketio-server.js @@ -8,6 +8,7 @@ var Selection = require('./selection'); var util = require('util'); var LZString = require('lz-string'); +var logger = require('../logger'); function EditorSocketIOServer(document, operations, docId, mayWrite) { EventEmitter.call(this); @@ -47,7 +48,11 @@ EditorSocketIOServer.prototype.addClient = function (socket) { console.log("User doesn't have the right to edit."); return; } - self.onOperation(socket, revision, operation, selection); + try { + self.onOperation(socket, revision, operation, selection); + } catch (err) { + socket.disconnect(); + } }); }); socket.on('get_operations', function (base, head) { @@ -82,8 +87,9 @@ EditorSocketIOServer.prototype.onOperation = function (socket, revision, operati selection && Selection.fromJSON(selection) ); } catch (exc) { - console.error("Invalid operation received: " + exc); - return; + logger.error("Invalid operation received: "); + logger.error(exc); + throw new Error(exc); } try { @@ -99,7 +105,8 @@ EditorSocketIOServer.prototype.onOperation = function (socket, revision, operati ); this.isDirty = true; } catch (exc) { - console.error(exc); + logger.error(exc); + throw new Error(exc); } }; -- cgit v1.2.3