[英]Error can't be catched?: NodeJS/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-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);
}
}
我得到了錯誤,但指令已經發出,我得到了日期(所以捕獲錯誤永遠不起作用?)
你的問題是 network.getContract 返回一個 Promise,所以這里發生的事情是你的代碼在 Promise 解決之前移動通過那一行,所以你的 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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.