diff --git a/src/app/api/purchase-orders/upload/route.ts b/src/app/api/purchase-orders/upload/route.ts index e9b920e..ae7fb86 100644 --- a/src/app/api/purchase-orders/upload/route.ts +++ b/src/app/api/purchase-orders/upload/route.ts @@ -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", {