summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2015-07-14 23:38:51 +0800
committerWu Cheng-Han2015-07-14 23:38:51 +0800
commit1b92300445e8a0d76a6778c4e2802b6d2ff631a5 (patch)
tree9cefb044d84241366055c372fae4d68e1cd5e0b3 /lib
parentf678bf7205d9dd922d863f1449304767c9f3c0d7 (diff)
Handle when OT throw Error, will log it then disconnect socket client
Diffstat (limited to 'lib')
-rwxr-xr-xlib/ot/editor-socketio-server.js15
1 files changed, 11 insertions, 4 deletions
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);
}
};