From b216baf6192f834971b9c7ab2c17085de1af92ec Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 6 Oct 2024 00:37:12 +0200 Subject: [PATCH] requestPart try catch --- lib/fediblock.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/fediblock.js b/lib/fediblock.js index a18c9f4..4f1ddd3 100644 --- a/lib/fediblock.js +++ b/lib/fediblock.js @@ -20,15 +20,24 @@ module.exports = async (client, apex, app) => { const ac = new AbortController(), timeout = setTimeout(() => { setImmediate(() => ac.abort()) - }, constant.abort_timeout), - response = await fetch(uri, { + }, constant.abort_timeout) + try { + const response = await fetch(uri, { headers: { 'User-Agent': constant.agent }, signal: ac.signal, keepalive: false, timeout: constant.timeout, }) - setImmediate(() => clearTimeout(timeout)) - return await response.json() + setImmediate(() => clearTimeout(timeout)) + return await response.json() + } catch (e) { + setImmediate(() => { + clearTimeout(timeout) + ac.abort() + }) + return + // console.error(e) + } }, scanInstance = async instance => { const json = await requestPart(`https://${instance}/api/v1/instance/domain_blocks`) @@ -108,7 +117,7 @@ module.exports = async (client, apex, app) => { app.locals.peers++ await scanInstance(instance) } catch (e) { - // console.error(e) + console.error(e) } } yield 0