From 9493303add1f92d6fb90ed2a9253574c93304b26 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 22 Oct 2025 12:01:45 +0200 Subject: [PATCH] fix handle `fetch` error. closes #31 --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c9099c3..a9456a7 100644 --- a/index.js +++ b/index.js @@ -152,7 +152,22 @@ async function testRetrieval({ }) { const url = `https://${clientAddress}.${CDN_HOSTNAME}/${pieceCid}` console.log('Fetching', url) - const res = await fetch(url) + + let res + try { + res = await fetch(url) + } catch (err) { + console.error( + 'ALERT Cannot retrieve data set %s piece %sfrom %s via %s: %s', + String(dataSetId), + String(pieceId), + botLocation ?? '', + url, + err, + ) + return + } + console.log('-> Status code:', res.status) if (!res.ok) { const reason = (await res.text()).trim()