Read the extract response correctly, and fail visibly
/ocr-extract answers { extracted: {...}, raw: "..." }. The client checked
`fields` first and `extracted` second, which was right by luck — but an
extraction that returned nothing, or threw, did so silently: the button
went back to idle and the operator had no way to tell a read from a
no-read.
Now an empty or failed extraction says so under the field, and either
way the UPLOAD survives. The file is already stored and referenced; a
failed read only means the fields are not pre-filled, which someone can
recover by typing. Losing the upload because the read failed would not
be recoverable.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
43259b378c
commit
e32916cad3
@ -36,11 +36,22 @@ export default function FileField({ field, value, instanceId, activityUid, onCha
|
||||
|
||||
if (isOcr) {
|
||||
setBusy('Reading the document…')
|
||||
// Extraction failing must NOT lose the upload. The file is already
|
||||
// stored and referenced; a failed read just means the fields are not
|
||||
// pre-filled, which is recoverable by typing. Swallowing the upload
|
||||
// because the OCR errored would not be.
|
||||
try {
|
||||
const out = await client.ocrExtract(ref, ctx)
|
||||
const fields = out?.fields ?? out?.extracted ?? out?.data ?? out
|
||||
if (fields && typeof fields === 'object') {
|
||||
// The endpoint answers { extracted: {...}, raw: "..." }.
|
||||
const fields = out?.extracted ?? out?.fields ?? out?.data ?? null
|
||||
if (fields && typeof fields === 'object' && Object.keys(fields).length) {
|
||||
setExtracted(fields)
|
||||
onExtract?.(fields)
|
||||
} else {
|
||||
setErr({ status: '', message: 'Uploaded, but nothing could be read from this document.' })
|
||||
}
|
||||
} catch (ox) {
|
||||
setErr({ status: ox.status ?? '', message: 'Uploaded, but reading it failed — ' + (ox.message || 'unknown error') })
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user