From: Ardis Lu Date: Thu, 8 Aug 2024 06:19:46 +0000 (-0700) Subject: Fix page getting stuck on RPC error X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=914c0fae0edd503cb49b2cddd45a78dae8bf95fa;p=block-hash-calculator Fix page getting stuck on RPC error Now the page will swallow the error so the user can re-try the query. --- diff --git a/index.html b/index.html index f358760..76e5adb 100644 --- a/index.html +++ b/index.html @@ -74,18 +74,17 @@ method: 'eth_getBlockByNumber', params: [`0x${BigInt(num).toString(16)}`, false] }) - }).then(r => r.json()); + }).then(r => r.json()).catch(e => e); const block = response?.result; - if (block === undefined) { - return; - } - const { header, rlp, hash } = calculate(block); + if (block !== undefined) { + const { header, rlp, hash } = calculate(block); - document.querySelector('#out-header').textContent = `[\n ${header.join(',\n ')}\n]`; - document.querySelector('#out-rlp').textContent = rlp; - document.querySelector('#out-hash').textContent = hash; - document.querySelector('output').style.setProperty('display', 'unset'); + document.querySelector('#out-header').textContent = `[\n ${header.join(',\n ')}\n]`; + document.querySelector('#out-rlp').textContent = rlp; + document.querySelector('#out-hash').textContent = hash; + document.querySelector('output').style.setProperty('display', 'unset'); + } e.target.removeAttribute('data-loading'); });