diff --git a/src/components/FileField.jsx b/src/components/FileField.jsx index 2ba0a8a..a640da9 100644 --- a/src/components/FileField.jsx +++ b/src/components/FileField.jsx @@ -36,11 +36,22 @@ export default function FileField({ field, value, instanceId, activityUid, onCha if (isOcr) { setBusy('Reading the document…') - const out = await client.ocrExtract(ref, ctx) - const fields = out?.fields ?? out?.extracted ?? out?.data ?? out - if (fields && typeof fields === 'object') { - setExtracted(fields) - onExtract?.(fields) + // 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) + // 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) {