From: Ardis Lu Date: Sun, 29 Jun 2025 05:42:15 +0000 (-0700) Subject: Improve response error handling X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=90a68ce50c00c6be3bdb36265b11fc6f9b3ddf0e;p=block-hash-calculator Improve response error handling --- diff --git a/index.html b/index.html index f69ac2e..a25ab30 100644 --- a/index.html +++ b/index.html @@ -77,17 +77,22 @@ }).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');