Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,10 @@ File.prototype.startResumableUpload_ = function(stream, metadata) {
var writeStream = request(reqOpts);
writeStream.callback = util.noop;

writeStream.on('error', function(err) {
handleError(err);
});

This comment was marked as spam.

writeStream.on('complete', function(res) {
util.handleResp(null, res, res.body, function(err, data) {
if (err) {
Expand Down Expand Up @@ -1056,7 +1060,6 @@ File.prototype.startResumableUpload_ = function(stream, metadata) {
}

stream.emit('error', err);
stream.end();
}
};

Expand Down
38 changes: 38 additions & 0 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,44 @@ describe('File', function() {
writable.write('data');
});

it('should re-emit errors', function(done) {
var error = new Error('Error.');

This comment was marked as spam.

var requestCount = 0;
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts, cb) {
requestCount++;

// respond to creation POST.
if (requestCount === 1) {
cb(null, null, { headers: { location: 'http://resume' }});
return;
}

// create an authorized request for the first PUT.
if (requestCount === 2) {
cb.onAuthorized(null, { headers: {} });
}
};

// respond to first upload PUT request.
request_Override = function() {
var stream = through();
setImmediate(function() {
stream.emit('error', error);
});
return stream;
};

var stream = duplexify();

stream
.on('error', function(err) {
assert.equal(err, error);
done();
});

file.startResumableUpload_(stream);
});

it('should start a simple upload if specified', function(done) {
var writable = file.createWriteStream({
metadata: METADATA,
Expand Down