Refactor installation to work out a few bugs and to make it cleaner. Transactions now reject on fail-responses, still need to update other places.

This commit is contained in:
Simo Kinnunen
2014-09-04 19:40:54 +09:00
parent f91bf901fa
commit c5a4727ae3
7 changed files with 159 additions and 233 deletions

View File

@@ -3,6 +3,7 @@ var Promise = require('bluebird')
module.exports = function GroupServiceFactory(
socket
, TransactionService
, TransactionError
) {
var groupService = {
}
@@ -21,12 +22,13 @@ module.exports = function GroupServiceFactory(
}
}
})
return tx.promise.then(function(result) {
if (!result.success) {
return tx.promise
.then(function(result) {
return result.device
})
.catch(TransactionError, function() {
throw new Error('Device refused to join the group')
}
return result.device
})
})
}
groupService.kick = function (device, force) {
@@ -43,12 +45,13 @@ module.exports = function GroupServiceFactory(
}
}
})
return tx.promise.then(function(result) {
if (!result.success) {
throw new Error('Device refused to be kicked from the group')
}
return result.device
})
return tx.promise
.then(function(result) {
return result.device
})
.catch(TransactionError, function() {
throw new Error('Device refused to join the group')
})
}
return groupService