Skip to content

Commit

Permalink
Properly handle empty responses
Browse files Browse the repository at this point in the history
Obtain the HTTP status code from the
response object rather than the response
body.

FABN-1187 #done

Change-Id: I430fa2947671a9e3d8cf4f137b2f6afd013e1e3a
Signed-off-by: Gari Singh <[email protected]>
  • Loading branch information
mastersingh24 committed Mar 26, 2019
1 parent f476894 commit 1a7a53f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fabric-ca-client/lib/FabricCAClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const FabricCAClient = class {

if (!payload) {
return reject(new Error(
util.format('fabric-ca request %s failed with HTTP status code %s', api_method, JSON.parse(data).statusCode)));
util.format('fabric-ca request %s failed with HTTP status code %s', api_method, response.statusCode)));
}
// response should be JSON
let responseObj;
Expand Down Expand Up @@ -461,7 +461,7 @@ const FabricCAClient = class {

if (!payload) {
return reject(new Error(
util.format('Enrollment failed with HTTP status code', JSON.parse(data).statusCode)));
util.format('Enrollment failed with HTTP status code', response.statusCode)));
}
// response should be JSON
try {
Expand Down
6 changes: 4 additions & 2 deletions fabric-ca-client/test/FabricCAClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,11 @@ describe('FabricCAClient', () => {
// Create a mock response object...
const res = new events.EventEmitter();
res.setEncoding = function () { };
res.statusCode = 500;
callback(res);

// ...end with only status code being sent.
res.emit('end', '{"statusCode":500}');
res.emit('end');
return new events.EventEmitter();
});

Expand Down Expand Up @@ -1145,11 +1146,12 @@ describe('FabricCAClient', () => {
// Create a mock response object...
const res = new events.EventEmitter();
res.setEncoding = function () { };
res.statusCode = 500;
callback(res);

// ...end with only status code being sent.
res.emit('data');
res.emit('end', '{"statusCode":500}');
res.emit('end');
return new events.EventEmitter();
});

Expand Down
4 changes: 2 additions & 2 deletions test/scenario/chaincode/fabcar/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "~1.4.0",
"fabric-shim": "~1.4.0"
"fabric-contract-api": "unstable",
"fabric-shim": "unstable"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down

0 comments on commit 1a7a53f

Please sign in to comment.