From 8425cb894d4867d26fd5f7fae7862b0669f3c717 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Feb 2016 19:02:05 +0100 Subject: Error handling mini refractoring --- models/videos.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'models/videos.js') diff --git a/models/videos.js b/models/videos.js index 10abee6e7..6ea628373 100644 --- a/models/videos.js +++ b/models/videos.js @@ -50,7 +50,7 @@ VideosDB.create(params, function (err, video) { if (err) { - logger.error('Cannot insert this video into database.', { error: err }) + logger.error('Cannot insert this video into database.') return callback(err) } @@ -82,7 +82,7 @@ }, function () { VideosDB.create(to_add, function (err, videos) { if (err) { - logger.error('Cannot insert this remote video.', { error: err }) + logger.error('Cannot insert this remote video.') return callback(err) } @@ -94,7 +94,7 @@ function get (id, callback) { VideosDB.findById(id, function (err, video) { if (err) { - logger.error('Cannot get this video.', { error: err }) + logger.error('Cannot get this video.') return callback(err) } @@ -120,14 +120,14 @@ VideosDB.findById(id, function (err, video) { if (err || !video) { if (!err) err = new Error('Cannot find this video.') - logger.error('Cannot find this video.', { error: err }) + logger.error('Cannot find this video.') return callback(err) } if (video.namePath === null) { var error_string = 'Cannot remove the video of another pod.' logger.error(error_string) - return callback(null, false, video) + return callback(new Error(error_string), false, video) } callback(null, true, video) @@ -137,7 +137,7 @@ function list (callback) { VideosDB.find(function (err, videos_list) { if (err) { - logger.error('Cannot get list of the videos.', { error: err }) + logger.error('Cannot get the list of the videos.') return callback(err) } @@ -149,7 +149,7 @@ // If namePath is not null this is *our* video VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { if (err) { - logger.error('Cannot get list of the videos.', { error: err }) + logger.error('Cannot get the list of owned videos.') return callback(err) } @@ -160,13 +160,13 @@ function removeOwned (id, callback) { VideosDB.findByIdAndRemove(id, function (err, video) { if (err) { - logger.error('Cannot remove the torrent.', { error: err }) + logger.error('Cannot remove the torrent.') return callback(err) } fs.unlink(uploadDir + video.namePath, function (err) { if (err) { - logger.error('Cannot remove this video file.', { error: err }) + logger.error('Cannot remove this video file.') return callback(err) } @@ -222,7 +222,7 @@ function search (name, callback) { VideosDB.find({ name: new RegExp(name) }, function (err, videos) { if (err) { - logger.error('Cannot search the videos.', { error: err }) + logger.error('Cannot search the videos.') return callback(err) } -- cgit v1.2.3