Skip to content

Commit

Permalink
Merge pull request #24 from Wilzi/master
Browse files Browse the repository at this point in the history
feat(request-error): send response statusMessage in error if exists
  • Loading branch information
drawain authored Sep 8, 2016
2 parents 941c14d + 5a7f12f commit b1f170f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RequestWrapper.prototype = {

if (!this.requestOptions.allowEmptyResponse && !response.body) {
logger.error('server_error', 'empty response data');
return reject(new SuiteRequestError('Empty http response', 500));
return reject(new SuiteRequestError('Empty http response', 500, response.statusMessage));
}

if (response.headers['content-type'] === 'application/json') {
Expand Down
14 changes: 14 additions & 0 deletions wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ describe('Wrapper', function() {
expect(err).to.be.an.instanceof(SuiteRequestError);
expect(err.message).to.eql('Empty http response');
expect(err.code).to.eql(500);
expect(err.data).to.eql({ replyText: 'Empty http response' });
return;
}
throw new Error('Error should have been thrown');
});

it('should throw error with status message if response body is empty and status message exists', function *() {
apiResponse.body = '';
apiResponse.statusMessage = 'dummy status message';

try {
yield wrapper.send();
} catch (err) {
expect(err.data).to.eql(apiResponse.statusMessage);
return;
}
throw new Error('Error should have been thrown');
Expand Down

0 comments on commit b1f170f

Please sign in to comment.