]> git.ardis.lu - block-hash-calculator/commitdiff
Improve response error handling
authorArdis Lu <ardisglu@gmail.com>
Sun, 29 Jun 2025 05:42:15 +0000 (22:42 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 29 Jun 2025 05:42:15 +0000 (22:42 -0700)
index.html

index f69ac2e8290dc8573d51a8357f6a15b4160efb48..a25ab306f9437f624f927a672e6271363bccacca 100644 (file)
       }).then(r => r.json()).catch(e => e);
 
       const block = response?.result;
-      if (block !== undefined) {
+      if (block === undefined) {
+        document.querySelector('#out-header').textContent = `Unable to retrieve block header. Error: ${response?.message ?? 'Other'}`;
+        document.querySelector('#out-encoded').textContent = 'N/A';
+        document.querySelector('#out-hash').textContent = 'N/A';
+      }
+      else if (block === null) {
+        document.querySelector('#out-header').textContent = 'Unable to calculate block hash. Block number is greater than latest block.';
+        document.querySelector('#out-encoded').textContent = 'N/A';
+        document.querySelector('#out-hash').textContent = 'N/A';
+      }
+      else {
         const { header, encoded, hash } = block?.l1BatchTimestamp && block?.l1BatchNumber ? calculateZkSync(block) : calculate(block);
         document.querySelector('#out-header').textContent = `[\n  ${header.join(',\n  ')}\n]`;
         document.querySelector('#out-encoded').textContent = encoded;
         document.querySelector('#out-hash').textContent = hash;
       }
-      else {
-        document.querySelector('#out-header').textContent = `Unable to retrieve block header. Error: ${response?.message ?? 'Other'}`;
-        document.querySelector('#out-encoded').textContent = 'N/A';
-        document.querySelector('#out-hash').textContent = 'N/A';
-      }
       document.querySelector('output').style.setProperty('display', 'unset');
 
       e.target.removeAttribute('data-loading');
This page took 0.030698 seconds and 4 git commands to generate.