fix bug by completing the PR #650 (#824)

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
Denis Barbaron
2025-01-20 17:53:57 +01:00
committed by GitHub
parent 0b21f0c4fc
commit 9b8738cdbb

View File

@@ -138,6 +138,7 @@ function addUserDevice(req, res) {
datautil.normalize(device, req.user)
if (!deviceutil.isAddable(device, req.user)) {
lockutil.unlockDevice(lock)
return res.status(403).json({
success: false
, description: 'Device is being used or not available'
@@ -147,6 +148,7 @@ function addUserDevice(req, res) {
// Timer will be called if no JoinGroupMessage is received till 5 seconds
var responseTimer = setTimeout(function() {
req.options.channelRouter.removeListener(wireutil.global, messageListener)
lockutil.unlockDevice(lock)
return res.status(504).json({
success: false
, description: 'Device is not responding'
@@ -158,6 +160,7 @@ function addUserDevice(req, res) {
if (message.serial === serial && message.owner.email === req.user.email) {
clearTimeout(responseTimer)
req.options.channelRouter.removeListener(wireutil.global, messageListener)
lockutil.unlockDevice(lock)
return res.json({
success: true
@@ -191,13 +194,10 @@ function addUserDevice(req, res) {
)
])
}
return false
})
.catch(function(err) {
apiutil.internalError(res, `Failed to take control of ${serial} device: `, err.stack)
})
.finally(function() {
lockutil.unlockDevice(lock)
apiutil.internalError(res, `Failed to take control of ${serial} device: `, err.stack)
})
}