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:
@@ -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
@@ -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 (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user