]> git.ardis.lu - block-hash-calculator/commitdiff
Fix page getting stuck on RPC error
authorArdis Lu <ardisglu@gmail.com>
Thu, 8 Aug 2024 06:19:46 +0000 (23:19 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 8 Aug 2024 06:19:46 +0000 (23:19 -0700)
Now the page will swallow the error so the user can re-try the query.

index.html

index f3587606bf290225e67c65d21ead0ac764a0e881..76e5adbdd0b445ad2808ac7271603c316375da34 100644 (file)
           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');
     });
This page took 0.034613 seconds and 4 git commands to generate.