зеркало из https://github.com/mozilla/makedrive.git
Fix issues #72 - Callback already called
This commit is contained in:
Родитель
6def40f44e
Коммит
05fc29a8bc
|
@ -61,8 +61,8 @@ function handleRequest(data, fs, syncObject, syncSession, socket, callback) {
|
||||||
// UPSTREAM - DIFFS
|
// UPSTREAM - DIFFS
|
||||||
handleDiffRequest();
|
handleDiffRequest();
|
||||||
} else {
|
} else {
|
||||||
syncObject.state = sync.SYNC_ERROR;
|
syncObject.state = syncObject.SYNC_ERROR;
|
||||||
syncObject.emit('error', new Error(data.content));
|
syncObject.emit('error', data.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ function init(url, token, sync, fs, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClose(code, data) {
|
function handleClose(code, data) {
|
||||||
|
if(data) {
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -84,6 +85,9 @@ function init(url, token, sync, fs, callback) {
|
||||||
sync.state = sync.SYNC_DISCONNECTED;
|
sync.state = sync.SYNC_DISCONNECTED;
|
||||||
return sync.emit('disconnected');
|
return sync.emit('disconnected');
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
data = 'Websocket unexpectedly closed.';
|
||||||
|
}
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
var error = new Error(code + ': ' + data);
|
var error = new Error(code + ': ' + data);
|
||||||
|
|
|
@ -38,7 +38,7 @@ module.exports = function( server ) {
|
||||||
var sync = Sync.create( authData.username, authData.sessionId );
|
var sync = Sync.create( authData.username, authData.sessionId );
|
||||||
sync.setSocket( ws );
|
sync.setSocket( ws );
|
||||||
|
|
||||||
ws.on('close', sync.onClose);
|
ws.on('close', sync.onClose());
|
||||||
|
|
||||||
ws.on('message', function(data, flags) {
|
ws.on('message', function(data, flags) {
|
||||||
if(!flags || (flags && !flags.binary)) {
|
if(!flags || (flags && !flags.binary)) {
|
||||||
|
|
|
@ -76,6 +76,7 @@ function handleRequest(data) {
|
||||||
that.init();
|
that.init();
|
||||||
} else {
|
} else {
|
||||||
response = SyncMessage.error.locked;
|
response = SyncMessage.error.locked;
|
||||||
|
response.content = { error: "Current sync in progress! Try again later!" };
|
||||||
}
|
}
|
||||||
that.socket.send(response.stringify());
|
that.socket.send(response.stringify());
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче