diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index e881122194..0ae37f7cdd 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -2535,10 +2535,11 @@ export class Connection { */ async getConfirmedBlock(slot: number): Promise { 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'); diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 7b54a276e1..33f2385c2b 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -1120,13 +1120,15 @@ test('get confirmed block', async () => { params: [Number.MAX_SAFE_INTEGER], }, { - error: null, + error: { + message: `Block not available for slot ${Number.MAX_SAFE_INTEGER}`, + }, result: null, }, ]); await expect( connection.getConfirmedBlock(Number.MAX_SAFE_INTEGER), - ).rejects.toThrow(); + ).rejects.toThrow(`Block not available for slot ${Number.MAX_SAFE_INTEGER}`); }); test('get recent blockhash', async () => {