fix: fix TypeError when confirmed block is not found (#13264)

This commit is contained in:
Justin Starry
2020-10-29 11:23:07 +08:00
committed by GitHub
parent 781b92a8c0
commit bc16b58d75
2 changed files with 8 additions and 5 deletions

View File

@@ -2535,10 +2535,11 @@ export class Connection {
*/
async getConfirmedBlock(slot: number): Promise<ConfirmedBlock> {
const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot]);
const {result, error} = GetConfirmedBlockRpcResult(unsafeRes);
if (error) {
throw new Error('failed to get confirmed block: ' + result.error.message);
const res = GetConfirmedBlockRpcResult(unsafeRes);
if (res.error) {
throw new Error('failed to get confirmed block: ' + res.error.message);
}
const result = res.result;
assert(typeof result !== 'undefined');
if (!result) {
throw new Error('Confirmed block ' + slot + ' not found');