Here is my code snippet
import { fetch } from 'BlackBerry-Dynamics-for-React-Native-Networking';
async componentDidMount() {
try {
let res = await fetch('http://my-private-url.com',
{
method : 'GET',
headers : {}
});
let response = await res.text();
// let response = await res.json(); // tried this method as well, getting same behaviour
} catch (error) {
console.log('errr-----', error);
}
}
I am getting the following error sometimes and sometimes it works fine (Note - on the same API, same response) :-
Error: The specified blob is invalid
at Object.promiseMethodWrapper [as readAsText] (D:\PE-Code\rester\ds\node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:103)
at EventTarget.readAsText (D:\PE-Code\rester\ds\node_modules\BlackBerry-Dynamics-for-React-Native-Networking\js\FileReader.js:118)
at readBlobAsText (D:\PE-Code\rester\ds\node_modules\BlackBerry-Dynamics-for-React-Native-Networking\js\fetch.js:206)
at Response.Body.text (D:\PE-Code\rester\ds\node_modules\BlackBerry-Dynamics-for-React-Native-Networking\js\fetch.js:300)
at RootDashboard.componentDidMount$ (D:\PE-Code\rester\ds\src\components\dashboards\RootDashboard.js:48)
at tryCatch (D:\PE-Code\rester\ds\node_modules\regenerator-runtime\runtime.js:63)
at Generator.invoke [as _invoke] (D:\PE-Code\rester\ds\node_modules\regenerator-runtime\runtime.js:293)
at Generator.next (D:\PE-Code\rester\ds\node_modules\regenerator-runtime\runtime.js:118)
at tryCatch (D:\PE-Code\rester\ds\node_modules\regenerator-runtime\runtime.js:63)
at invoke (D:\PE-Code\rester\ds\node_modules\regenerator-runtime\runtime.js:154)
Can you help me by suggesting what I might be doing wrong?
Am I using the fetch from BlackBerry-Dynamics-for-React-Native-Networking correctly?
React Native Version - 0.63.4, BB Dynamics SDK version - 8.1
Sometimes it works fine, sometimes it gives error.
I am making 3-4 API requests at the time of loading of my application, sometimes the 3rd request fails, sometimes the 1st one fails and happens like this randomly.
I logged the xhr before this line - https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/blob/master/modules/BlackBerry-Dynamics-for-React-Native-Networking/js/fetch.js#L483
Some of my findings which tell me whether I got a successful response or not -
The blob size when we get successful response is significantly greater (around 1200) than when we get an error response (around 50) on the same API, same response.
When I get a successful response, the responseURL is correct but when I don't get a successful response, the responseURL is - "http://10.0.2.2:8081/symbolicate".
Also, most of the times, I get an error on the first time my app is loaded after going through the BB authorization screens. It works fine most of the times after I refresh my app.
XHR when I get a successful response - Successful Response XHR
XHR when I get error - Error
Do these findings help in any way?
are you able to reach the private URL from another BlackBerry Dynamics application? The SDK must be in an authenticated state prior to calling the networking APIs. I recommend testing if you can reach the URL in our BasicNetworkingSample or from BlackBerry Access (if available).
BasicNetworkingSample: https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/tree/master/SampleApplications/BasicNetworking