From 097d2fdcf4fed26b67cf77e0ec2100a6b7877932 Mon Sep 17 00:00:00 2001 From: DEls Date: Wed, 19 Aug 2026 22:19:21 +0200 Subject: [PATCH] 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 --- src/app/api/purchase-orders/upload/route.ts | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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", {