获取错误:http:从Hyperledger Composer中的事务处理器函数读取关闭的响应正文



我有一个用简单的BNA运行的结构网络。该BNA定义了两种类型的参与者,即。企业和个人。在这里,每个人都与公司有关系,如下所示(首席技术官文件(:

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

我想做什么:

  1. 使用事务处理器功能创建企业:成功
  2. 使用事务处理器功能创建人员:失败

以下是 #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.");
}
}

我的查询中的片段.qry:

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

因此,当我尝试#2时,我收到以下错误:

错误:

2 未知:执行链码时出错:返回失败的事务:错误:错误:http:在关闭的响应正文上读取

但是,当我尝试直接从 swagger 执行查询时,它会成功运行。

我正在使用:

超级账本结构:1.1 超级账本编辑器:0.19.8

我是否错过了此检查或步骤?

对于第 2 项 - 您实际上不需要每次都执行命名查询。

您可以按如下方式进行等效检查("他已经存在吗?"((其中trxn下面是事务定义中定义的事务对象等(:

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

最新更新