fix(consent): avoid banner flashing on reload
Initialize consent state from cookie synchronously so the banner only shows when no choice was made. fix(api): fail-soft when DB schema missing Return null/empty content for CMS endpoints when migrations are not applied instead of crashing with Prisma P2021/P2022. fix(n8n): parse status response defensively Handle empty/invalid JSON bodies from n8n to prevent activity feed from getting stuck. Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -54,7 +54,8 @@ export async function GET(request: NextRequest) {
|
||||
const res = await fetch(statusUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
// n8n sometimes responds with empty body; we'll parse defensively below.
|
||||
Accept: "application/json",
|
||||
...(process.env.N8N_SECRET_TOKEN && {
|
||||
Authorization: `Bearer ${process.env.N8N_SECRET_TOKEN}`,
|
||||
}),
|
||||
@@ -71,7 +72,21 @@ export async function GET(request: NextRequest) {
|
||||
throw new Error(`n8n error: ${res.status} - ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
const raw = await res.text().catch(() => "");
|
||||
if (!raw || !raw.trim()) {
|
||||
throw new Error("Empty response body received from n8n");
|
||||
}
|
||||
|
||||
let data: unknown;
|
||||
try {
|
||||
data = JSON.parse(raw);
|
||||
} catch (parseError) {
|
||||
// Sometimes upstream sends HTML or a partial response; include a snippet for debugging.
|
||||
const snippet = raw.slice(0, 240);
|
||||
throw new Error(
|
||||
`Invalid JSON from n8n (${res.status}): ${snippet}${raw.length > 240 ? "…" : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
// n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt.
|
||||
const statusData = Array.isArray(data) ? data[0] : data;
|
||||
|
||||
Reference in New Issue
Block a user