Getting Error: http: read on closed response body from Transaction Processor function in Hyperledger Composer

十年热恋 提交于 2019-12-25 00:56:14

问题


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:


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");


来源:https://stackoverflow.com/questions/52223280/getting-error-http-read-on-closed-response-body-from-transaction-processor-fun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!