From 51d505bd9f4c1bad778015300b032276652d2af8 Mon Sep 17 00:00:00 2001 From: ilhom Date: Sun, 28 Jun 2026 15:40:24 +0700 Subject: [PATCH] fix(frontend): surface validate timeout error message instead of 503 BFF validate route now returns 422 with base.message when finance service returns isSuccess=false (e.g. timeout on large file). validateBulkProductRoutingFile reads base.message from error responses so the toast shows the backend's readable message rather than "Validation failed: 503". Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../finance/costing/validate/bulk_product_routing/route.ts | 6 ++++++ src/services/finance/cost-import-api.ts | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/api/v1/finance/costing/validate/bulk_product_routing/route.ts b/src/app/api/v1/finance/costing/validate/bulk_product_routing/route.ts index a52dbd8..698a289 100644 --- a/src/app/api/v1/finance/costing/validate/bulk_product_routing/route.ts +++ b/src/app/api/v1/finance/costing/validate/bulk_product_routing/route.ts @@ -23,6 +23,12 @@ export async function POST(request: NextRequest) { metadata, ) + // Surface backend errors (e.g. timeout on very large files) as a non-2xx response + // so the frontend can display the message rather than showing an empty result. + if (res.base && !res.base.isSuccess) { + return NextResponse.json({ base: res.base }, { status: 422 }) + } + return NextResponse.json({ isValid: res.isValid, sheets: res.sheets.map((sheet) => ({ diff --git a/src/services/finance/cost-import-api.ts b/src/services/finance/cost-import-api.ts index 37c0083..2ecd952 100644 --- a/src/services/finance/cost-import-api.ts +++ b/src/services/finance/cost-import-api.ts @@ -227,7 +227,10 @@ export async function validateBulkProductRoutingFile( headers: { "Content-Type": "application/json" }, body: JSON.stringify({ fileContent, fileName: file.name }), }) - if (!res.ok) throw new Error(`Validation failed: ${res.status}`) + if (!res.ok) { + const errJson = await res.json().catch(() => null) + throw new Error(errJson?.base?.message || `Validation failed: ${res.status}`) + } const json = await res.json() if (!json.base?.isSuccess && json.base?.isSuccess !== undefined) {