]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - models/poolRequests.js
Error handling mini refractoring
[github/Chocobozzz/PeerTube.git] / models / poolRequests.js
index 0f488ef04202e2af649e4f91f6274262b2c163fe..962e75e6a5bab36fac95e95c7073e5afc07a9df4 100644 (file)
     logger.debug('Add request to the pool requests.', { id: id, type: type, request: request })
 
     PoolRequestsDB.findOne({ id: id }, function (err, entity) {
-      if (err) logger.error(err)
+      if (err) {
+        logger.error('Cannot find one pool request.', { error: err })
+        return // Abort
+      }
 
       if (entity) {
         if (entity.type === type) {
-          logger.error(new Error('Cannot insert two same requests.'))
-          return
+          logger.error('Cannot insert two same requests.')
+          return // Abort
         }
 
         // Remove the request of the other type
         PoolRequestsDB.remove({ id: id }, function (err) {
-          if (err) logger.error(err)
+          if (err) {
+            logger.error('Cannot remove a pool request.', { error: err })
+            return // Abort
+          }
         })
       } else {
         PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) {
-          if (err) logger.error(err)
+          logger.error('Cannot create a pool request.', { error: err })
+          return // Abort
         })
       }
     })
@@ -54,7 +61,7 @@
     PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
       if (err) {
         logger.error('Cannot remove requests from the pool requests database.', { error: err })
-        return
+        return // Abort
       }
 
       logger.info('Pool requests flushed.')