diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 19:02:05 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 19:02:05 +0100 |
commit | 8425cb894d4867d26fd5f7fae7862b0669f3c717 (patch) | |
tree | 5e2f00a8219e198f2dd074ca13f3ae681174228f | |
parent | dac0a5319ab1c52a0958647b1593f85339b77e29 (diff) | |
download | PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.gz PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.zst PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.zip |
Error handling mini refractoring
-rw-r--r-- | controllers/api/v1/pods.js | 7 | ||||
-rw-r--r-- | controllers/api/v1/videos.js | 4 | ||||
-rw-r--r-- | helpers/peertubeCrypto.js | 12 | ||||
-rw-r--r-- | helpers/utils.js | 2 | ||||
-rw-r--r-- | lib/friends.js | 24 | ||||
-rw-r--r-- | lib/poolRequests.js | 43 | ||||
-rw-r--r-- | lib/videos.js | 4 | ||||
-rw-r--r-- | lib/webtorrent.js | 2 | ||||
-rw-r--r-- | middlewares/reqValidators/pods.js | 5 | ||||
-rw-r--r-- | models/pods.js | 2 | ||||
-rw-r--r-- | models/poolRequests.js | 19 | ||||
-rw-r--r-- | models/videos.js | 20 |
12 files changed, 86 insertions, 58 deletions
diff --git a/controllers/api/v1/pods.js b/controllers/api/v1/pods.js index 29517ba8e..456f53dea 100644 --- a/controllers/api/v1/pods.js +++ b/controllers/api/v1/pods.js | |||
@@ -39,13 +39,13 @@ | |||
39 | 39 | ||
40 | fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { | 40 | fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { |
41 | if (err) { | 41 | if (err) { |
42 | logger.error('Cannot read cert file.', { error: err }) | 42 | logger.error('Cannot read cert file.') |
43 | return next(err) | 43 | return next(err) |
44 | } | 44 | } |
45 | 45 | ||
46 | Videos.listOwned(function (err, videos_list) { | 46 | Videos.listOwned(function (err, videos_list) { |
47 | if (err) { | 47 | if (err) { |
48 | logger.error('Cannot get the list of owned videos.', { error: err }) | 48 | logger.error('Cannot get the list of owned videos.') |
49 | return next(err) | 49 | return next(err) |
50 | } | 50 | } |
51 | 51 | ||
@@ -78,7 +78,8 @@ | |||
78 | 78 | ||
79 | Videos.removeAllRemotesOf(url, function (err) { | 79 | Videos.removeAllRemotesOf(url, function (err) { |
80 | if (err) logger.error('Cannot remove all remote videos of %s.', url) | 80 | if (err) logger.error('Cannot remove all remote videos of %s.', url) |
81 | logger.info('%s pod removed.', url) | 81 | else logger.info('%s pod removed.', url) |
82 | |||
82 | res.sendStatus(204) | 83 | res.sendStatus(204) |
83 | }) | 84 | }) |
84 | }) | 85 | }) |
diff --git a/controllers/api/v1/videos.js b/controllers/api/v1/videos.js index 7792059ca..eec95c801 100644 --- a/controllers/api/v1/videos.js +++ b/controllers/api/v1/videos.js | |||
@@ -56,7 +56,7 @@ | |||
56 | 56 | ||
57 | videos.seed(video_file.path, function (err, torrent) { | 57 | videos.seed(video_file.path, function (err, torrent) { |
58 | if (err) { | 58 | if (err) { |
59 | logger.error('Cannot seed this video.', { error: err }) | 59 | logger.error('Cannot seed this video.') |
60 | return next(err) | 60 | return next(err) |
61 | } | 61 | } |
62 | 62 | ||
@@ -70,7 +70,7 @@ | |||
70 | Videos.add(video_data, function (err) { | 70 | Videos.add(video_data, function (err) { |
71 | if (err) { | 71 | if (err) { |
72 | // TODO unseed the video | 72 | // TODO unseed the video |
73 | logger.error('Cannot insert this video in the database.', { error: err }) | 73 | logger.error('Cannot insert this video in the database.') |
74 | return next(err) | 74 | return next(err) |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/helpers/peertubeCrypto.js b/helpers/peertubeCrypto.js index 3e757659b..36271dba9 100644 --- a/helpers/peertubeCrypto.js +++ b/helpers/peertubeCrypto.js | |||
@@ -101,7 +101,7 @@ | |||
101 | logger.info('Generating a RSA key...') | 101 | logger.info('Generating a RSA key...') |
102 | openssl.exec('genrsa', { 'out': certDir + 'peertube.key.pem', '2048': false }, function (err) { | 102 | openssl.exec('genrsa', { 'out': certDir + 'peertube.key.pem', '2048': false }, function (err) { |
103 | if (err) { | 103 | if (err) { |
104 | logger.error('Cannot create private key on this pod.', { error: err }) | 104 | logger.error('Cannot create private key on this pod.') |
105 | return callback(err) | 105 | return callback(err) |
106 | } | 106 | } |
107 | logger.info('RSA key generated.') | 107 | logger.info('RSA key generated.') |
@@ -109,7 +109,7 @@ | |||
109 | logger.info('Manage public key...') | 109 | logger.info('Manage public key...') |
110 | openssl.exec('rsa', { 'in': certDir + 'peertube.key.pem', 'pubout': true, 'out': certDir + 'peertube.pub' }, function (err) { | 110 | openssl.exec('rsa', { 'in': certDir + 'peertube.key.pem', 'pubout': true, 'out': certDir + 'peertube.pub' }, function (err) { |
111 | if (err) { | 111 | if (err) { |
112 | logger.error('Cannot create public key on this pod .', { error: err }) | 112 | logger.error('Cannot create public key on this pod.') |
113 | return callback(err) | 113 | return callback(err) |
114 | } | 114 | } |
115 | 115 | ||
@@ -122,9 +122,7 @@ | |||
122 | 122 | ||
123 | function generatePassword (callback) { | 123 | function generatePassword (callback) { |
124 | crypto.randomBytes(32, function (err, buf) { | 124 | crypto.randomBytes(32, function (err, buf) { |
125 | if (err) { | 125 | if (err) return callback(err) |
126 | return callback(err) | ||
127 | } | ||
128 | 126 | ||
129 | callback(null, buf.toString('utf8')) | 127 | callback(null, buf.toString('utf8')) |
130 | }) | 128 | }) |
@@ -139,9 +137,7 @@ | |||
139 | 137 | ||
140 | function symetricEncrypt (text, callback) { | 138 | function symetricEncrypt (text, callback) { |
141 | generatePassword(function (err, password) { | 139 | generatePassword(function (err, password) { |
142 | if (err) { | 140 | if (err) return callback(err) |
143 | return callback(err) | ||
144 | } | ||
145 | 141 | ||
146 | var cipher = crypto.createCipher(algorithm, password) | 142 | var cipher = crypto.createCipher(algorithm, password) |
147 | var crypted = cipher.update(text, 'utf8', 'hex') | 143 | var crypted = cipher.update(text, 'utf8', 'hex') |
diff --git a/helpers/utils.js b/helpers/utils.js index bd0557977..92684ea81 100644 --- a/helpers/utils.js +++ b/helpers/utils.js | |||
@@ -8,7 +8,7 @@ | |||
8 | } | 8 | } |
9 | 9 | ||
10 | function cleanForExit (webtorrent_process) { | 10 | function cleanForExit (webtorrent_process) { |
11 | logger.info('Gracefully exiting') | 11 | logger.info('Gracefully exiting.') |
12 | process.kill(-webtorrent_process.pid) | 12 | process.kill(-webtorrent_process.pid) |
13 | } | 13 | } |
14 | 14 | ||
diff --git a/lib/friends.js b/lib/friends.js index b0086a38b..badf09c7d 100644 --- a/lib/friends.js +++ b/lib/friends.js | |||
@@ -30,8 +30,7 @@ | |||
30 | function addVideoToFriends (video) { | 30 | function addVideoToFriends (video) { |
31 | // To avoid duplicates | 31 | // To avoid duplicates |
32 | var id = video.name + video.magnetUri | 32 | var id = video.name + video.magnetUri |
33 | // namePath is null | 33 | // ensure namePath is null |
34 | // TODO | ||
35 | video.namePath = null | 34 | video.namePath = null |
36 | PoolRequests.addRequest(id, 'add', video) | 35 | PoolRequests.addRequest(id, 'add', video) |
37 | } | 36 | } |
@@ -51,13 +50,15 @@ | |||
51 | logger.info('Make friends!') | 50 | logger.info('Make friends!') |
52 | fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { | 51 | fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { |
53 | if (err) { | 52 | if (err) { |
54 | logger.error('Cannot read public cert.', { error: err }) | 53 | logger.error('Cannot read public cert.') |
55 | return callback(err) | 54 | return callback(err) |
56 | } | 55 | } |
57 | 56 | ||
58 | var urls = config.get('network.friends') | 57 | var urls = config.get('network.friends') |
59 | 58 | ||
60 | async.each(urls, computeForeignPodsList, function () { | 59 | async.each(urls, computeForeignPodsList, function (err) { |
60 | if (err) return callback(err) | ||
61 | |||
61 | logger.debug('Pods scores computed.', { pods_score: pods_score }) | 62 | logger.debug('Pods scores computed.', { pods_score: pods_score }) |
62 | var pods_list = computeWinningPods(urls, pods_score) | 63 | var pods_list = computeWinningPods(urls, pods_score) |
63 | logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list }) | 64 | logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list }) |
@@ -72,7 +73,8 @@ | |||
72 | // Let's give 1 point to the pod we ask the friends list | 73 | // Let's give 1 point to the pod we ask the friends list |
73 | pods_score[url] = 1 | 74 | pods_score[url] = 1 |
74 | 75 | ||
75 | getForeignPodsList(url, function (foreign_pods_list) { | 76 | getForeignPodsList(url, function (err, foreign_pods_list) { |
77 | if (err) return callback(err) | ||
76 | if (foreign_pods_list.length === 0) return callback() | 78 | if (foreign_pods_list.length === 0) return callback() |
77 | 79 | ||
78 | async.each(foreign_pods_list, function (foreign_pod, callback_each) { | 80 | async.each(foreign_pods_list, function (foreign_pod, callback_each) { |
@@ -108,7 +110,10 @@ | |||
108 | 110 | ||
109 | // Get the list of our videos to send to our new friends | 111 | // Get the list of our videos to send to our new friends |
110 | Videos.listOwned(function (err, videos_list) { | 112 | Videos.listOwned(function (err, videos_list) { |
111 | if (err) throw err | 113 | if (err) { |
114 | logger.error('Cannot get the list of videos we own.') | ||
115 | return callback(err) | ||
116 | } | ||
112 | 117 | ||
113 | var data = { | 118 | var data = { |
114 | url: http + '://' + host + ':' + port, | 119 | url: http + '://' + host + ':' + port, |
@@ -145,7 +150,7 @@ | |||
145 | poolRequests.activate() | 150 | poolRequests.activate() |
146 | 151 | ||
147 | if (err) { | 152 | if (err) { |
148 | logger.error('There was some errors when we wanted to make friends.', { error: err }) | 153 | logger.error('There was some errors when we wanted to make friends.') |
149 | return callback(err) | 154 | return callback(err) |
150 | } | 155 | } |
151 | 156 | ||
@@ -212,8 +217,9 @@ | |||
212 | var path = '/api/' + constants.API_VERSION + '/pods' | 217 | var path = '/api/' + constants.API_VERSION + '/pods' |
213 | 218 | ||
214 | request.get(url + path, function (err, response, body) { | 219 | request.get(url + path, function (err, response, body) { |
215 | if (err) throw err | 220 | if (err) return callback(err) |
216 | callback(JSON.parse(body)) | 221 | |
222 | callback(null, JSON.parse(body)) | ||
217 | }) | 223 | }) |
218 | } | 224 | } |
219 | })() | 225 | })() |
diff --git a/lib/poolRequests.js b/lib/poolRequests.js index f4ab434ad..ccc3489ab 100644 --- a/lib/poolRequests.js +++ b/lib/poolRequests.js | |||
@@ -44,7 +44,7 @@ | |||
44 | if (!callback) callback = function () {} | 44 | if (!callback) callback = function () {} |
45 | 45 | ||
46 | Pods.list(function (err, pods) { | 46 | Pods.list(function (err, pods) { |
47 | if (err) throw err | 47 | if (err) return callback(err) |
48 | 48 | ||
49 | var params = { | 49 | var params = { |
50 | encrypt: true, | 50 | encrypt: true, |
@@ -59,7 +59,7 @@ | |||
59 | } else if (type === 'remove') { | 59 | } else if (type === 'remove') { |
60 | params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove' | 60 | params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove' |
61 | } else { | 61 | } else { |
62 | throw new Error('Unkown pool request type.') | 62 | return callback(new Error('Unkown pool request type.')) |
63 | } | 63 | } |
64 | 64 | ||
65 | var bad_pods = [] | 65 | var bad_pods = [] |
@@ -91,7 +91,10 @@ | |||
91 | logger.info('Making pool requests to friends.') | 91 | logger.info('Making pool requests to friends.') |
92 | 92 | ||
93 | PoolRequests.list(function (err, pool_requests) { | 93 | PoolRequests.list(function (err, pool_requests) { |
94 | if (err) throw err | 94 | if (err) { |
95 | logger.error('Cannot get the list of pool requests.', { err: err }) | ||
96 | return // Abort | ||
97 | } | ||
95 | 98 | ||
96 | if (pool_requests.length === 0) return | 99 | if (pool_requests.length === 0) return |
97 | 100 | ||
@@ -114,7 +117,8 @@ | |||
114 | requests_to_make.remove.requests.push(pool_request.request) | 117 | requests_to_make.remove.requests.push(pool_request.request) |
115 | requests_to_make.remove.ids.push(pool_request._id) | 118 | requests_to_make.remove.ids.push(pool_request._id) |
116 | } else { | 119 | } else { |
117 | throw new Error('Unkown pool request type.') | 120 | logger.error('Unkown pool request type.', { request_type: pool_request.type }) |
121 | return // abort | ||
118 | } | 122 | } |
119 | 123 | ||
120 | callback_each() | 124 | callback_each() |
@@ -142,7 +146,10 @@ | |||
142 | 146 | ||
143 | function removeBadPods () { | 147 | function removeBadPods () { |
144 | Pods.findBadPods(function (err, pods) { | 148 | Pods.findBadPods(function (err, pods) { |
145 | if (err) throw err | 149 | if (err) { |
150 | logger.error('Cannot find bad pods.', { error: err }) | ||
151 | return // abort | ||
152 | } | ||
146 | 153 | ||
147 | if (pods.length === 0) return | 154 | if (pods.length === 0) return |
148 | 155 | ||
@@ -150,15 +157,20 @@ | |||
150 | var ids = pluck(pods, '_id') | 157 | var ids = pluck(pods, '_id') |
151 | 158 | ||
152 | Videos.removeAllRemotesOf(urls, function (err, r) { | 159 | Videos.removeAllRemotesOf(urls, function (err, r) { |
153 | if (err) logger.error('Cannot remove videos from a pod that we removing.', { error: err }) | 160 | if (err) { |
154 | var videos_removed = r.result.n | 161 | logger.error('Cannot remove videos from a pod that we removing.', { error: err }) |
155 | logger.info('Removed %d videos.', videos_removed) | 162 | } else { |
163 | var videos_removed = r.result.n | ||
164 | logger.info('Removed %d videos.', videos_removed) | ||
165 | } | ||
156 | 166 | ||
157 | Pods.removeAllByIds(ids, function (err, r) { | 167 | Pods.removeAllByIds(ids, function (err, r) { |
158 | if (err) logger.error('Cannot remove bad pods.', { error: err }) | 168 | if (err) { |
159 | 169 | logger.error('Cannot remove bad pods.', { error: err }) | |
160 | var pods_removed = r.result.n | 170 | } else { |
161 | logger.info('Removed %d pods.', pods_removed) | 171 | var pods_removed = r.result.n |
172 | logger.info('Removed %d pods.', pods_removed) | ||
173 | } | ||
162 | }) | 174 | }) |
163 | }) | 175 | }) |
164 | }) | 176 | }) |
@@ -167,9 +179,12 @@ | |||
167 | function updatePodsScore (good_pods, bad_pods) { | 179 | function updatePodsScore (good_pods, bad_pods) { |
168 | logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) | 180 | logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) |
169 | 181 | ||
170 | Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS) | 182 | Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS, function (err) { |
183 | if (err) logger.error('Cannot increment scores of good pods.') | ||
184 | }) | ||
185 | |||
171 | Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) { | 186 | Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) { |
172 | if (err) throw err | 187 | if (err) logger.error('Cannot increment scores of bad pods.') |
173 | removeBadPods() | 188 | removeBadPods() |
174 | }) | 189 | }) |
175 | } | 190 | } |
diff --git a/lib/videos.js b/lib/videos.js index 5d23070a7..0da7715c4 100644 --- a/lib/videos.js +++ b/lib/videos.js | |||
@@ -28,14 +28,14 @@ | |||
28 | function seedAllExisting (callback) { | 28 | function seedAllExisting (callback) { |
29 | Videos.listOwned(function (err, videos_list) { | 29 | Videos.listOwned(function (err, videos_list) { |
30 | if (err) { | 30 | if (err) { |
31 | logger.error('Cannot get list of the videos to seed.', { error: err }) | 31 | logger.error('Cannot get list of the videos to seed.') |
32 | return callback(err) | 32 | return callback(err) |
33 | } | 33 | } |
34 | 34 | ||
35 | async.each(videos_list, function (video, each_callback) { | 35 | async.each(videos_list, function (video, each_callback) { |
36 | seed(uploadDir + video.namePath, function (err) { | 36 | seed(uploadDir + video.namePath, function (err) { |
37 | if (err) { | 37 | if (err) { |
38 | logger.error('Cannot seed this video.', { error: err }) | 38 | logger.error('Cannot seed this video.') |
39 | return callback(err) | 39 | return callback(err) |
40 | } | 40 | } |
41 | 41 | ||
diff --git a/lib/webtorrent.js b/lib/webtorrent.js index d1ca3c9f2..d0db6e066 100644 --- a/lib/webtorrent.js +++ b/lib/webtorrent.js | |||
@@ -62,7 +62,7 @@ | |||
62 | try { | 62 | try { |
63 | wt.remove(magnetUri, callback) | 63 | wt.remove(magnetUri, callback) |
64 | } catch (err) { | 64 | } catch (err) { |
65 | console.log('Cannot remove the torrent from WebTorrent') | 65 | console.log('Cannot remove the torrent from WebTorrent.') |
66 | return callback(null) | 66 | return callback(null) |
67 | } | 67 | } |
68 | 68 | ||
diff --git a/middlewares/reqValidators/pods.js b/middlewares/reqValidators/pods.js index 499cafd8f..4d649b486 100644 --- a/middlewares/reqValidators/pods.js +++ b/middlewares/reqValidators/pods.js | |||
@@ -12,7 +12,10 @@ | |||
12 | 12 | ||
13 | function makeFriends (req, res, next) { | 13 | function makeFriends (req, res, next) { |
14 | friends.hasFriends(function (err, has_friends) { | 14 | friends.hasFriends(function (err, has_friends) { |
15 | if (err) return next(err) | 15 | if (err) { |
16 | logger.error('Cannot know if we have friends.', { error: err }) | ||
17 | res.sendStatus(500) | ||
18 | } | ||
16 | 19 | ||
17 | if (has_friends === true) { | 20 | if (has_friends === true) { |
18 | // We need to quit our friends before make new ones | 21 | // We need to quit our friends before make new ones |
diff --git a/models/pods.js b/models/pods.js index 395b1e0b1..04fd042c3 100644 --- a/models/pods.js +++ b/models/pods.js | |||
@@ -61,7 +61,7 @@ | |||
61 | function list (callback) { | 61 | function list (callback) { |
62 | PodsDB.find(function (err, pods_list) { | 62 | PodsDB.find(function (err, pods_list) { |
63 | if (err) { | 63 | if (err) { |
64 | logger.error('Cannot get the list of the pods.', { error: err }) | 64 | logger.error('Cannot get the list of the pods.') |
65 | return callback(err) | 65 | return callback(err) |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/models/poolRequests.js b/models/poolRequests.js index 0f488ef04..962e75e6a 100644 --- a/models/poolRequests.js +++ b/models/poolRequests.js | |||
@@ -26,21 +26,28 @@ | |||
26 | logger.debug('Add request to the pool requests.', { id: id, type: type, request: request }) | 26 | logger.debug('Add request to the pool requests.', { id: id, type: type, request: request }) |
27 | 27 | ||
28 | PoolRequestsDB.findOne({ id: id }, function (err, entity) { | 28 | PoolRequestsDB.findOne({ id: id }, function (err, entity) { |
29 | if (err) logger.error(err) | 29 | if (err) { |
30 | logger.error('Cannot find one pool request.', { error: err }) | ||
31 | return // Abort | ||
32 | } | ||
30 | 33 | ||
31 | if (entity) { | 34 | if (entity) { |
32 | if (entity.type === type) { | 35 | if (entity.type === type) { |
33 | logger.error(new Error('Cannot insert two same requests.')) | 36 | logger.error('Cannot insert two same requests.') |
34 | return | 37 | return // Abort |
35 | } | 38 | } |
36 | 39 | ||
37 | // Remove the request of the other type | 40 | // Remove the request of the other type |
38 | PoolRequestsDB.remove({ id: id }, function (err) { | 41 | PoolRequestsDB.remove({ id: id }, function (err) { |
39 | if (err) logger.error(err) | 42 | if (err) { |
43 | logger.error('Cannot remove a pool request.', { error: err }) | ||
44 | return // Abort | ||
45 | } | ||
40 | }) | 46 | }) |
41 | } else { | 47 | } else { |
42 | PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) { | 48 | PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) { |
43 | if (err) logger.error(err) | 49 | logger.error('Cannot create a pool request.', { error: err }) |
50 | return // Abort | ||
44 | }) | 51 | }) |
45 | } | 52 | } |
46 | }) | 53 | }) |
@@ -54,7 +61,7 @@ | |||
54 | PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { | 61 | PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { |
55 | if (err) { | 62 | if (err) { |
56 | logger.error('Cannot remove requests from the pool requests database.', { error: err }) | 63 | logger.error('Cannot remove requests from the pool requests database.', { error: err }) |
57 | return | 64 | return // Abort |
58 | } | 65 | } |
59 | 66 | ||
60 | logger.info('Pool requests flushed.') | 67 | logger.info('Pool requests flushed.') |
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 @@ | |||
50 | 50 | ||
51 | VideosDB.create(params, function (err, video) { | 51 | VideosDB.create(params, function (err, video) { |
52 | if (err) { | 52 | if (err) { |
53 | logger.error('Cannot insert this video into database.', { error: err }) | 53 | logger.error('Cannot insert this video into database.') |
54 | return callback(err) | 54 | return callback(err) |
55 | } | 55 | } |
56 | 56 | ||
@@ -82,7 +82,7 @@ | |||
82 | }, function () { | 82 | }, function () { |
83 | VideosDB.create(to_add, function (err, videos) { | 83 | VideosDB.create(to_add, function (err, videos) { |
84 | if (err) { | 84 | if (err) { |
85 | logger.error('Cannot insert this remote video.', { error: err }) | 85 | logger.error('Cannot insert this remote video.') |
86 | return callback(err) | 86 | return callback(err) |
87 | } | 87 | } |
88 | 88 | ||
@@ -94,7 +94,7 @@ | |||
94 | function get (id, callback) { | 94 | function get (id, callback) { |
95 | VideosDB.findById(id, function (err, video) { | 95 | VideosDB.findById(id, function (err, video) { |
96 | if (err) { | 96 | if (err) { |
97 | logger.error('Cannot get this video.', { error: err }) | 97 | logger.error('Cannot get this video.') |
98 | return callback(err) | 98 | return callback(err) |
99 | } | 99 | } |
100 | 100 | ||
@@ -120,14 +120,14 @@ | |||
120 | VideosDB.findById(id, function (err, video) { | 120 | VideosDB.findById(id, function (err, video) { |
121 | if (err || !video) { | 121 | if (err || !video) { |
122 | if (!err) err = new Error('Cannot find this video.') | 122 | if (!err) err = new Error('Cannot find this video.') |
123 | logger.error('Cannot find this video.', { error: err }) | 123 | logger.error('Cannot find this video.') |
124 | return callback(err) | 124 | return callback(err) |
125 | } | 125 | } |
126 | 126 | ||
127 | if (video.namePath === null) { | 127 | if (video.namePath === null) { |
128 | var error_string = 'Cannot remove the video of another pod.' | 128 | var error_string = 'Cannot remove the video of another pod.' |
129 | logger.error(error_string) | 129 | logger.error(error_string) |
130 | return callback(null, false, video) | 130 | return callback(new Error(error_string), false, video) |
131 | } | 131 | } |
132 | 132 | ||
133 | callback(null, true, video) | 133 | callback(null, true, video) |
@@ -137,7 +137,7 @@ | |||
137 | function list (callback) { | 137 | function list (callback) { |
138 | VideosDB.find(function (err, videos_list) { | 138 | VideosDB.find(function (err, videos_list) { |
139 | if (err) { | 139 | if (err) { |
140 | logger.error('Cannot get list of the videos.', { error: err }) | 140 | logger.error('Cannot get the list of the videos.') |
141 | return callback(err) | 141 | return callback(err) |
142 | } | 142 | } |
143 | 143 | ||
@@ -149,7 +149,7 @@ | |||
149 | // If namePath is not null this is *our* video | 149 | // If namePath is not null this is *our* video |
150 | VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { | 150 | VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { |
151 | if (err) { | 151 | if (err) { |
152 | logger.error('Cannot get list of the videos.', { error: err }) | 152 | logger.error('Cannot get the list of owned videos.') |
153 | return callback(err) | 153 | return callback(err) |
154 | } | 154 | } |
155 | 155 | ||
@@ -160,13 +160,13 @@ | |||
160 | function removeOwned (id, callback) { | 160 | function removeOwned (id, callback) { |
161 | VideosDB.findByIdAndRemove(id, function (err, video) { | 161 | VideosDB.findByIdAndRemove(id, function (err, video) { |
162 | if (err) { | 162 | if (err) { |
163 | logger.error('Cannot remove the torrent.', { error: err }) | 163 | logger.error('Cannot remove the torrent.') |
164 | return callback(err) | 164 | return callback(err) |
165 | } | 165 | } |
166 | 166 | ||
167 | fs.unlink(uploadDir + video.namePath, function (err) { | 167 | fs.unlink(uploadDir + video.namePath, function (err) { |
168 | if (err) { | 168 | if (err) { |
169 | logger.error('Cannot remove this video file.', { error: err }) | 169 | logger.error('Cannot remove this video file.') |
170 | return callback(err) | 170 | return callback(err) |
171 | } | 171 | } |
172 | 172 | ||
@@ -222,7 +222,7 @@ | |||
222 | function search (name, callback) { | 222 | function search (name, callback) { |
223 | VideosDB.find({ name: new RegExp(name) }, function (err, videos) { | 223 | VideosDB.find({ name: new RegExp(name) }, function (err, videos) { |
224 | if (err) { | 224 | if (err) { |
225 | logger.error('Cannot search the videos.', { error: err }) | 225 | logger.error('Cannot search the videos.') |
226 | return callback(err) | 226 | return callback(err) |
227 | } | 227 | } |
228 | 228 | ||