Handle when OT throw Error, will log it then disconnect socket client
This commit is contained in:
parent
f678bf7205
commit
1b92300445
1 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue