Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #75 from zapier/stash_file_streams_content
Browse files Browse the repository at this point in the history
Raise Exception for Bad Requests When Stashing A File
  • Loading branch information
mojowen authored Mar 29, 2018
2 parents b97d54d + 971a501 commit 9b0cbda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/tools/create-file-stasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const createFileStasher = input => {
} else {
newBufferStringStream = response.content;
}

knownLength =
knownLength || response.getHeader('content-length');
const cd = response.getHeader('content-disposition');
Expand All @@ -141,8 +140,8 @@ const createFileStasher = input => {
fileContentType
);
};

if (isStreamed) {
maybeResponse.throwForStatus();
return maybeResponse.buffer().then(parseFinalResponse);
} else {
return parseFinalResponse(maybeResponse);
Expand Down
22 changes: 22 additions & 0 deletions test/tools/file-stasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');

const should = require('should');
const nock = require('nock');

const mocky = require('./mocky');

Expand Down Expand Up @@ -115,6 +116,27 @@ describe('file upload', () => {
.catch(done);
});

it('should throwForStatus if bad status', done => {
mocky.mockRpcCall(mocky.fakeSignedPostData);
mocky.mockUpload();

nock('http://example.com')
.get('/stream-bytes')
.reply(401);

const request = createAppRequestClient(input);
const file = request({
url: 'http://example.com/stream-bytes',
raw: true
});
stashFile(file)
.catch(err => {
should(err.message).containEql('Received 401 code from');
done();
})
.catch(done);
});

it('should upload a resolved buffer', done => {
mocky.mockRpcCall(mocky.fakeSignedPostData);
mocky.mockUpload();
Expand Down

0 comments on commit 9b0cbda

Please sign in to comment.