From 90a68ce50c00c6be3bdb36265b11fc6f9b3ddf0e Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 28 Jun 2025 22:42:15 -0700 Subject: [PATCH] Improve response error handling --- index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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'); -- 2.47.3