Getting Error: http: read on closed response body

2019-08-23 01:35发布

I've a fabric network running with a simple BNA. This BNA defines two types of participants viz. Corporate and Person. Here, each Person has a relationship with the corporate as shown below (cto file):

participant Corporate identified by corporateId {
    o String corporateId
    o String corporateName
}
participant Person identified by personId {
    o String personId
    --> Corporate corporate
}

What I'm trying to do:

  1. Create a Corporate using Transaction Processor Function: Success
  2. Create a Person using Transaction Processor Function: Failure

Following is the snippet from transaction processor function for #2:

let corporateIdExpected = personDetails.corporate;

if(corporateIdExpected && corporateIdExpected != '') {
    let corporateRetrieved = await query("GetCorporateByCorporateId", {corporateId: corporateIdExpected});
    if(!corporateRetrieved || corporateRetrieved == '') {
        throw new Error("Corporate details not valid. Please check if your corporate is present on the network.");
    }
}

Snippet from my queries.qry:

query GetCorporateByCorporateId {
  description: "Returns all corporates in the registry"
  statement:  
      SELECT  org.samplenetwork.participants.Corporate
          WHERE (corporateId == _$corporateId)
}

So, I get the following error when I try the #2:

Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: Error: http: read on closed response body

However, when I try to execute the query directly from the swagger, it runs successfully.

I'm using:

Hyperledger Fabric: 1.1 Hyperledger Composer: 0.19.8

Am I missing out any checks or steps for this one?

1条回答
我命由我不由天
2楼-- · 2019-08-23 02:20

for item 2 - you don't really need to execute a named query each time.

You can do the equivalent check ("does he exist already?") as follows (where trxn below is the transaction object defined in your transaction definition etc):

const personRegistry = await getParticipantRegistry('org.acme.example.Person');
console.log("The person identifier to check is " + trxn.corporate.getIdentifier() ) 

const exists = await personRegistry.exists(trxn.corporate.getIdentifier() ) ;

console.log("exists is set to " + exists); // boolean

if (exists)
        console.log("he exists") 
else
        console.log("he doesn't exist");
查看更多
登录 后发表回答