0

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 -

  1. 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.

  2. 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".

  3. 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?

1 Answers1

0

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

  • How can I know if my SDK is in an authenticated state or not? Also, I'm not sure if you missed it or read it but it works also sometimes. Another scenario that is occurring is that at the time of loading the application, 3-4 different APIs are being called, sometimes it gets stuck on the 3rd one, sometimes on the 1st and like this randomly. – Tanuj Chawla Apr 05 '21 at 17:08
  • Thank you for the clarification. If the app goes through the activation/authorization screens then you will be authenticated. Can you confirm what version of React-Native you are using and what version of BlackBerry Dynamics you are using? Also, are you targeting Android or iOS? – JeffinWithYa Apr 06 '21 at 13:57
  • Yup, I'm going through the authorization screens. I upgraded my React Native app from 0.62.2 to 0.63.4. So current version - 0.63.4. Blackberry Dynamics SDK version - 8.1. Currently targeting android, will require this for IOS also. – Tanuj Chawla Apr 07 '21 at 08:13
  • Thanks. The issue might be related to de-allocating blob resources. We cannot de-allocate blob resources in React-Native, so you need to explicitly de-allocate it. Check out this example from the BasicNetworking sample (relevant code snippet is in-line comment): https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/blob/4785aacb1fb385366200d190b040f7720e55c034/SampleApplications/BasicNetworking/App.js#L184 – JeffinWithYa Apr 07 '21 at 18:23
  • Thanks. I don't think that is the issue as whenever I get a successful response, I don't get this blob error. 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 – Tanuj Chawla Apr 08 '21 at 09:29
  • Some of my findings which tell me whether I got a successful response or not - 1. 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. 2. 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". Do these findings help in any way? – Tanuj Chawla Apr 08 '21 at 09:29
  • What type of response are you expecting? I recommend trying the unit tests to verify you are getting the correct response. Here are the unit tests that you can use to verify a successful response: https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/blob/master/SampleApplications/UnitTests/tests/specs/testFetch.js – JeffinWithYa Apr 08 '21 at 13:38
  • Thanks. The test cases are not helping much as still couldn't identify the cause of the issue, it just seems random as sometimes it works and sometimes it doesn't. I just attached a couple of screenshots to the issue above, please look at them. Also, another observation that I made is that - 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. – Tanuj Chawla Apr 12 '21 at 08:48
  • I cannot identify a particular Dynamics SDK issue that might cause this error. However, it could be resulting from an incorrect response from your backend. Can you verify that you are getting the correct response from the endpoint you're trying to reach when these failures happen? It might be helpful to introduce some re-try logic into your application when the response fails. – JeffinWithYa Apr 12 '21 at 16:17
  • If you can recreate the issue on a public url please let me know. We can try to recreate the issue from there. – JeffinWithYa Apr 12 '21 at 17:13
  • Thank you for the suggestion. Was able to make it work after adding some retry functionality. – Tanuj Chawla Apr 20 '21 at 08:20
  • Glad to hear it. Just as an FYI a new version of the SDK will be releasing in June with more support for blob responses. – JeffinWithYa Apr 20 '21 at 18:15
  • Great! Looking forward to it. – Tanuj Chawla Apr 21 '21 at 15:54
  • Hi Jeffin, Is there any way to get the authorized user's details like the email through which he logged into blackberry dynamics? – Tanuj Chawla Apr 26 '21 at 14:53