Skip to content

Commit

Permalink
Fix server crash when upload failed on Youtube
Browse files Browse the repository at this point in the history
Server was crashing when Youtube returned an error
on an upload. The error returned by Youtube in the
request body wasn't analyzed.
  • Loading branch information
maxime-beguin committed Apr 18, 2019
1 parent 0b8e4a3 commit aab7760
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 9.0.2 / YYYY-MM-DD

## BUG FIXES

- Fix server crash when uploading on Youtube failed

# 9.0.1 / 2018-11-16

## BUG FIXES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ YoutubeProvider.prototype.uploadResumable = function(mediaFilePath, uploadParams
process.logger.debug('Upload progress', progress);
});
resumableUpload.on('error', function(error) {
process.logger.debug('Upload error', error);
process.logger.error('Upload error', error && error.message);
if (resumableUpload.retry === 0) {
callback(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,25 @@ ResumableUpload.prototype.upload = function() {

// Send request and start upload if success
request.post(options, function(err, res, body) {
if (body) {
body = JSON.parse(body);

if (body.error) {
self.retry = 0;
self.emit('error', new Error(body.error.message));
return;
}
}

if (err || !res.headers.location) {
self.emit('error', new Error(err));
self.emit('error', err);
if ((self.retry > 0) || (self.retry <= -1)) {
self.emit('progress', 'Retrying ...');
self.retry--;
self.upload();// retry
} else {
if (err)
self.emit('error', new Error(err));
self.emit('error', err);
else
self.emit('error', new Error('max try reached'));
return;
Expand Down

0 comments on commit aab7760

Please sign in to comment.