diff --git a/lib/sources/github.js b/lib/sources/github.js index b90b797..c17891e 100644 --- a/lib/sources/github.js +++ b/lib/sources/github.js @@ -39,14 +39,30 @@ var fetchTarball = function (source, dir, callback) { var options = { url: source.url + '/tarball/' + branch, headers: headers } request(options) - .pipe(gunzip()) - .pipe(tar.Extract({ path: dir, strip: 1 })) + .on('response', function (resp) { + if (resp.statusCode >= 400) { + var err = new Error([ + 'Fetching', + options.url, + 'failed:', + resp.statusCode, + resp.statusMessage, + ].join(' ')); + return callback(err); + } + resp + .pipe(gunzip()) + .pipe(tar.Extract({ path: dir, strip: 1 })) + .on('error', function (err) { + return callback(err) + }) + .on('end', function () { + callback(null, dir) + }) + }) .on('error', function (err) { return callback(err) }) - .on('end', function () { - callback(null, dir) - }) } var fetchSource = function (source, dir, next) {