From 4c0942d11bea5b29c387888d3f81fcfffa70e846 Mon Sep 17 00:00:00 2001 From: Aleksei Pavlov Date: Fri, 19 Jun 2026 11:32:32 +0300 Subject: [PATCH] =?UTF-8?q?fix(zero):=20defensive=20fetch=20=E2=80=94=20do?= =?UTF-8?q?n't=20crash=20Server=20Components=20on=20engine=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - autogen page.js: wrap engineCall in try/catch (return null on any failure) - /zero page: use Promise.allSettled so one failed source doesn't break page Root cause was ENGINE_URL=host.docker.internal not resolving in coolify net, fixed at env level but defending code too so future quirks degrade gracefully. --- app/admin/(protected)/autogen/page.js | 17 +++++++++++------ app/zero/page.js | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/admin/(protected)/autogen/page.js b/app/admin/(protected)/autogen/page.js index 23942de..b07a812 100644 --- a/app/admin/(protected)/autogen/page.js +++ b/app/admin/(protected)/autogen/page.js @@ -11,12 +11,17 @@ const ENGINE_URL = process.env.ENGINE_URL || 'http://127.0.0.1:3030'; const ENGINE_SECRET = process.env.ENGINE_SECRET || 'zeropost_internal_2026'; async function engineCall(path) { - const res = await fetch(`${ENGINE_URL}${path}`, { - headers: { 'x-internal-secret': ENGINE_SECRET }, - cache: 'no-store', - }); - if (!res.ok) return null; - return res.json(); + try { + const res = await fetch(`${ENGINE_URL}${path}`, { + headers: { 'x-internal-secret': ENGINE_SECRET }, + cache: 'no-store', + }); + if (!res.ok) return null; + return await res.json(); + } catch (err) { + console.error(`[autogen/page] engineCall ${path} failed:`, err.message); + return null; + } } export default async function AutogenPage() { diff --git a/app/zero/page.js b/app/zero/page.js index 2f87467..1dc6964 100644 --- a/app/zero/page.js +++ b/app/zero/page.js @@ -11,10 +11,13 @@ export const metadata = { }; export default async function ZeroPage() { - const [notes, character] = await Promise.all([ + // defensive: один битый источник не должен валить страницу + const results = await Promise.allSettled([ listZeroNotes({ limit: 100 }), getZeroCharacter(), ]); + const notes = results[0].status === 'fulfilled' ? results[0].value : []; + const character = results[1].status === 'fulfilled' ? results[1].value : null; return ( <>