{"record":{"id":"63e6c40acc2b533c","repo":"NativeScript/NativeScript","slug":"could-not-read-formdata-body-as-text","errorCode":null,"errorMessage":"could not read FormData body as text","messagePattern":"could not read FormData body as text","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/fetch/index.mjs","lineNumber":298,"sourceCode":"                    return consumed(this) || Promise.resolve(this._bodyArrayBuffer);\n                } else {\n                    return this.blob().then(readBlobAsArrayBuffer);\n                }\n            };\n        }\n\n        this.text = function () {\n            var rejected = consumed(this);\n            if (rejected) {\n                return rejected;\n            }\n\n            if (this._bodyBlob) {\n                return readBlobAsText(this._bodyBlob);\n            } else if (this._bodyArrayBuffer) {\n                return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));\n            } else if (this._bodyFormData) {\n                throw new Error(\"could not read FormData body as text\");\n            } else {\n                return Promise.resolve(this._bodyText);\n            }\n        };\n\n        if (support.formData) {\n            this.formData = function () {\n                return this.text().then(decode);\n            };\n        }\n\n        this.json = function () {\n            return this.text().then(JSON.parse);\n        };\n\n        return this;\n    }\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/NativeScript/NativeScript/blob/6800aefa6511d23ddad8beb38ccc8541c5e91628/packages/core/fetch/index.mjs#L280-L316","documentation":"Same Body restriction as blob(): text() cannot represent a FormData body, so when _bodyFormData is set, text() throws Error \"could not read FormData body as text\". FormData must be consumed via formData() or serialized explicitly.","triggerScenarios":"Calling response.text() / request.text() on a body constructed from FormData — e.g. awaiting text() on an echo of a multipart request, or a logging layer that calls text() on every response.","commonSituations":"Logging interceptors that always call response.text(); unit tests constructing Response with FormData then reading text; generic download helpers ignoring body type.","solutions":["Branch on body type: if (body instanceof FormData) use formData()/entries, else text().","Serialize FormData manually (for (const [k,v] of form) ...) if text is truly needed.","Catch the error and fall back to another reader in generic pipelines."],"exampleFix":"// before\nconsole.log(await response.text()); // throws for FormData body\n// after\nif (response.body instanceof FormData) {\n  for (const [k, v] of response.body) console.log(k, v);\n} else {\n  console.log(await response.text());\n}","handlingStrategy":"type-guard","validationCode":"if (response.body instanceof FormData) {\n  // don't call text(); iterate formData() instead\n}","typeGuard":"function isFormDataBody(body) {\n  return typeof FormData !== 'undefined' && body instanceof FormData;\n}","tryCatchPattern":"try {\n  text = await response.text();\n} catch (e) {\n  if (e.message === 'could not read FormData body as text') {\n    text = [...response.body].map(([k, v]) => `${k}=${v}`).join('&');\n  } else throw e;\n}","preventionTips":["Guard text() readers with body instanceof FormData","In logging interceptors, special-case FormData bodies","Prefer formData()/entries() for multipart bodies"],"tags":["fetch","formdata","body"],"backgroundTag":"unsupported-body-type","analyzedSha":"6800aefa6511d23ddad8beb38ccc8541c5e91628","analyzedAt":"2026-08-30T20:04:56.809Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}