fetch
fetch copied to clipboard
"Cannot read property 'blobId' of undefined" from HTTP 204 No Content response
When performing a "DEL" request to a server which responds with an HTTP "204 No Content" response, I get the following error:
Cannot read property 'blobId' of undefined
This is a JSON dump of the symbolicated stack:
[
{
file: 'my-project-root/node_modules/react-native/Libraries/Blob/BlobManager.js',
methodName: 'createFromOptions',
arguments: [],
lineNumber: 113,
column: 34,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native-fetch-api/src/BlobResponse.js',
methodName: 'constructor',
arguments: [],
lineNumber: 6,
column: 51,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native-fetch-api/src/Fetch.js',
methodName: '__didCompleteNetworkResponse',
arguments: [],
lineNumber: 243,
column: 47,
collapse: false
},
{
file: null,
methodName: 'next',
arguments: [Array],
lineNumber: null,
column: null,
collapse: false
},
{
file: 'my-project-root/node_modules/@babel/runtime/helpers/asyncToGenerator.js',
methodName: 'asyncGeneratorStep',
arguments: [],
lineNumber: 3,
column: 24,
collapse: false
},
{
file: 'my-project-root/node_modules/@babel/runtime/helpers/asyncToGenerator.js',
methodName: '_next',
arguments: [],
lineNumber: 22,
column: 27,
collapse: false
},
{
file: 'my-project-root/node_modules/@babel/runtime/helpers/asyncToGenerator.js',
methodName: 'Promise$argument_0',
arguments: [],
lineNumber: 27,
column: 12,
collapse: false
},
{
file: '/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/5e6w3h5p/arm64-v8a/lib/InternalBytecode/InternalBytecode.js',
methodName: 'tryCallTwo',
arguments: [],
lineNumber: 61,
column: 9,
collapse: false
},
{
file: '/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/5e6w3h5p/arm64-v8a/lib/InternalBytecode/InternalBytecode.js',
methodName: 'doResolve',
arguments: [],
lineNumber: 216,
column: 25,
collapse: false
},
{
file: '/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/5e6w3h5p/arm64-v8a/lib/InternalBytecode/InternalBytecode.js',
methodName: 'Promise',
arguments: [],
lineNumber: 82,
column: 14,
collapse: false
},
{
file: 'my-project-root/node_modules/@babel/runtime/helpers/asyncToGenerator.js',
methodName: 'Promise$argument_0',
arguments: [],
lineNumber: 19,
column: 23,
collapse: false
},
{
file: null,
methodName: 'apply',
arguments: [Array],
lineNumber: null,
column: null,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native-fetch-api/src/Fetch.js',
methodName: 'Fetch',
arguments: [],
lineNumber: 254,
column: 5,
collapse: false
},
{
file: null,
methodName: 'apply',
arguments: [Array],
lineNumber: null,
column: null,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native-fetch-api/src/Fetch.js',
methodName: 'Networking.addListener$argument_1',
arguments: [],
lineNumber: 88,
column: 16,
collapse: false
},
{
file: null,
methodName: 'apply',
arguments: [Array],
lineNumber: null,
column: null,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js',
methodName: 'emit',
arguments: [],
lineNumber: 105,
column: 36,
collapse: true
},
{
file: null,
methodName: 'apply',
arguments: [Array],
lineNumber: null,
column: null,
collapse: false
},
{
file: 'my-project-root/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js',
methodName: '__callFunction',
arguments: [],
lineNumber: 427,
column: 32,
collapse: true
},
{
file: 'my-project-root/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js',
methodName: '__guard$argument_0',
arguments: [],
lineNumber: 113,
column: 26,
collapse: true
},
{
file: 'my-project-root/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js',
methodName: '__guard',
arguments: [],
lineNumber: 368,
column: 10,
collapse: true
},
{
file: 'my-project-root/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js',
methodName: '__guard$argument_0',
arguments: [],
lineNumber: 112,
column: 17,
collapse: true
}
]
Debugging
I removed the comments from some methods in Fetch.js
to reveal this:
LOG fetch __didCreateRequest {"requestId": 10}
LOG fetch __didReceiveNetworkResponse {"headers": {"Content-Encoding": "gzip", "Date": "Wed, 26 Apr 2023 21:54:56 GMT", "Strict-Transport-Security": "max-age=31536000; includeSubdomains;", "Vary": "Origin", "X-Appservices-Request-Id": "64499db00f4b7d44b52b7ad5", "X-Frame-Options": "DENY"}, "requestId": 10, "status": 204, "url": "http://10.0.2.2:9090/api/admin/v3.0/groups/643fd5800f4b7d44b53802af/apps/64499dae0f4b7d44b52b79d2"}
LOG fetch __didCompleteNetworkResponse {"didTimeOut": undefined, "errorMessage": null, "requestId": 10}
This shows that contrary to other responses the __didReceiveNetworkData
method is never called, which is why this._nativeResponse
remains undefined
, hence the error.
Workaround
I found that I can work around the issue by passing the extra reactNative: { textStreaming: true }
options to the fetch function:
await fetch(url, {
method: "DELETE",
reactNative: { textStreaming: true },
});