import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { reportFail } from "@/lib/render-pipeline/jobs"; // ── POST /api/ext/render/jobs/{jobId}/fail (E10) ───────────────────────────── // // Failure report. If retryable and attempts remain the server auto-creates the // next attempt and returns autoRequeued: true. export async function POST( req: NextRequest, { params }: { params: Promise<{ jobId: string }> } ) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { jobId } = await params; let body: { machineId?: string; stage?: string; exitCode?: number; errorMessage?: string; logTail?: string; logFileKey?: string; retryable?: boolean; }; try { body = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } if (!body.machineId) { return NextResponse.json({ error: "machineId is required" }, { status: 400 }); } try { const result = await reportFail(jobId, body.machineId, body); return NextResponse.json(result); } catch (err) { const { body: errBody, status } = toErrorResponse(err); return NextResponse.json(errBody, { status }); } }