Node.js 错误可能是';无法捕获?:节点/超级分类账
隐藏错误的最佳方法是什么 我想消除这个错误(隐藏它,或者如果有人知道问题出在哪里,就更好地解决它):Node.js 错误可能是';无法捕获?:节点/超级分类账,node.js,error-handling,try-catch,hyperledger,Node.js,Error Handling,Try Catch,Hyperledger,隐藏错误的最佳方法是什么 我想消除这个错误(隐藏它,或者如果有人知道问题出在哪里,就更好地解决它): 2019-12-12T17:43:54.626Z - error: [Orderer.js]: sendBroadcast - on error: "Error: 2 UNKNOWN: Stream removed\n at Object.exports.createStatusError (/home/hl-root/fabric-samples/fullgear-4n
2019-12-12T17:43:54.626Z - error: [Orderer.js]: sendBroadcast - on error: "Error: 2 UNKNOWN: Stream removed\n
at Object.exports.createStatusError (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/common.js:91:15)\n
at ClientDuplexStream._emitStatusIfDone (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client.js:233:26)\n
at ClientDuplexStream._receiveStatus (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client.js:211:8)\n
at Object.onReceiveStatus (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client_interceptors.js:1306:15)\n
at InterceptingListener._callNext (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client_interceptors.js:568:42)\n
at InterceptingListener.onReceiveStatus (/home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client_interceptors.js:618:8)\n
at /home/hl-root/fabric-samples/fullgear-4node-setup/app/node_modules/grpc/src/client_interceptors.js:1123:18"
Transaction submitted
我的代码如下所示:
while {
try {
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
const network = await gateway.getNetwork('mychannel');
const contract = network.getContract('chaincode');
await contract.submitTransaction('createTransaction', 'Transaction3', '1');
console.log('Transaction submitted');
}
catch (error) {
console.error(`Failed to submit transaction: ${error}`);
process.exit(1);
}
}
我得到了错误,但发出了指令,我得到了日期(所以catch错误永远不会起作用?您的问题是network.getContract返回一个承诺,所以这里发生的情况是,您的代码在承诺解析之前通过了那一行,所以您的try/catch在抛出错误之前完成,因此出现了异常。试试这个:
while {
try {
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
const network = await gateway.getNetwork('mychannel');
const contract = await network.getContract('chaincode');
await contract.submitTransaction('createTransaction', 'Transaction3', '1');
console.log('Transaction submitted');
}
catch (error) {
console.error(`Failed to submit transaction: ${error}`);
process.exit(1);
}
}