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) {