fix(zero): defensive fetch — don't crash Server Components on engine errors

- 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.
This commit is contained in:
Aleksei Pavlov
2026-06-19 11:32:32 +03:00
parent 8700b8fc69
commit 4c0942d11b
2 changed files with 15 additions and 7 deletions
+11 -6
View File
@@ -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() {
+4 -1
View File
@@ -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 (
<>