fix(api): surface real PocketBase error in /purchase-orders/upload

The catch block on batch_create only logged the PB error server-side
and returned a generic 500 'batch_create_failed', which forced
operators to dig through Coolify logs to find the real cause (e.g.
mime type not allowed, missing field). Now the response includes
pb_status, pb_message, and pb_data so the actual reason is visible
in the browser's Network tab and the dashboard's error toast.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DEls 2026-08-19 22:19:21 +02:00
parent 84ff4c25b2
commit 097d2fdcf4

View file

@ -61,8 +61,27 @@ export async function POST(request: Request) {
attempts: 0,
});
} catch (err) {
console.error("[po-upload] batch_create failed", { err: String(err) });
return NextResponse.json({ error: "batch_create_failed" }, { status: 500 });
// PocketBase's ClientResponseError carries the per-field validation
// details on err.response.data — surface them so the user can see
// exactly what went wrong (e.g. mime type not allowed, missing field).
const e = err as {
status?: number;
response?: { code?: number; data?: unknown; message?: string };
};
console.error("[po-upload] batch_create failed", {
err: String(err),
status: e?.status,
response: e?.response,
});
return NextResponse.json(
{
error: "batch_create_failed",
pb_status: e?.status ?? null,
pb_message: e?.response?.message ?? null,
pb_data: e?.response?.data ?? null,
},
{ status: 500 },
);
}
console.log("[po-upload] queued", {