{"record":{"id":"056e620ff6eaf1a1","repo":"NativeScript/NativeScript","slug":"failed-to-read-the-responsetext-property-from-x","errorCode":null,"errorMessage":"Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was '${this._responseType}').","messagePattern":"Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' \\(was '(.+?)'\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/xhr/index.ts","lineNumber":65,"sourceCode":"\tpublic get readyState(): number {\n\t\treturn this._readyState;\n\t}\n\n\tpublic get responseType(): string {\n\t\treturn this._responseType;\n\t}\n\n\tpublic set responseType(value: string) {\n\t\tif (value === XMLHttpRequestResponseType.empty || value in XMLHttpRequestResponseType) {\n\t\t\tthis._responseType = value;\n\t\t} else {\n\t\t\tthrow new Error(`Response type of '${value}' not supported.`);\n\t\t}\n\t}\n\n\tpublic get responseText(): string {\n\t\tif (this._responseType !== XMLHttpRequestResponseType.empty && this._responseType !== XMLHttpRequestResponseType.text) {\n\t\t\tthrow new Error(\"Failed to read the 'responseText' property from 'XMLHttpRequest': \" + \"The value is only accessible if the object's 'responseType' is '' or 'text' \" + `(was '${this._responseType}').`);\n\t\t}\n\n\t\tif (isFunction(this._responseTextReader)) {\n\t\t\treturn this._responseTextReader();\n\t\t}\n\n\t\treturn '';\n\t}\n\n\tpublic get response(): any {\n\t\tif (this._responseType === XMLHttpRequestResponseType.empty || this._responseType === XMLHttpRequestResponseType.text) {\n\t\t\tif (this._readyState !== this.LOADING && this._readyState !== this.DONE) {\n\t\t\t\treturn '';\n\t\t\t} else {\n\t\t\t\treturn this._response;\n\t\t\t}\n\t\t} else {\n\t\t\tif (this._readyState !== this.DONE) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/NativeScript/NativeScript/blob/6800aefa6511d23ddad8beb38ccc8541c5e91628/packages/core/xhr/index.ts#L47-L83","documentation":"Per the XHR spec, responseText is only readable when responseType is '' (empty) or 'text'. This XHR implementation enforces that: reading responseText after setting responseType to 'json', 'arraybuffer', or 'blob' throws this descriptive error.","triggerScenarios":"Setting `xhr.responseType = 'json'` (or 'arraybuffer'/'blob') and then reading `xhr.responseText` instead of `xhr.response`.","commonSituations":"Mixed code paths where one branch sets responseType for JSON and legacy code still reads responseText; copy-pasted handlers reading responseText regardless of the configured responseType.","solutions":["Read `xhr.response` instead of `xhr.responseText` when responseType is not '' or 'text'.","Reset `xhr.responseType = ''` (or 'text') before reading responseText — requires a new request for some implementations, so prefer reading response.","Branch on responseType in your load handler: use responseText for text modes, response otherwise."],"exampleFix":"// before\nxhr.responseType = 'json';\nxhr.onload = () => console.log(xhr.responseText); // throws\n\n// after\nxhr.responseType = 'json';\nxhr.onload = () => console.log(xhr.response);","handlingStrategy":"validation","validationCode":"const body = xhr.responseType === '' || xhr.responseType === 'text' ? xhr.responseText : xhr.response;","typeGuard":"function isTextResponseType(rt: string): boolean {\n  return rt === '' || rt === 'text';\n}","tryCatchPattern":"let body: any;\ntry {\n  body = xhr.responseText;\n} catch (e) {\n  if (/responseText/.test(e.message)) { body = xhr.response; } else { throw e; }\n}","preventionTips":["Read xhr.response unless responseType is '' or 'text'.","Branch on responseType in onload handlers.","Avoid mixing legacy responseText reads with typed responseType requests."],"tags":["xhr","http","responsetype"],"backgroundTag":"invalid-response-type","analyzedSha":"6800aefa6511d23ddad8beb38ccc8541c5e91628","analyzedAt":"2026-08-30T20:04:56.809Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}