Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down
5 changes: 4 additions & 1 deletion src/services/finance/cost-import-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading