iaphub / react-native-iaphub

The easiest way to implement IAP (In-app purchase) in your React Native app.
https://www.iaphub.com/
MIT License
317 stars 21 forks source link

Iaphub.buy(sku) suddenly stopped working. #133

Closed subalee closed 1 year ago

subalee commented 1 year ago

Since today I've been getting this error whenever I try to call Iaphub.buy(sku)

err Error: Network error, request to the Iaphub API failed (Unexpected token o in JSON at position 1)
    at Iaphub.error (index.js:1123)
    at Iaphub.request$ (index.js:1088)
    at tryCatch (runtime.js:63)
    at Generator.invoke [as _invoke] (runtime.js:294)
    at Generator.next (runtime.js:119)
    at tryCatch (runtime.js:63)
    at invoke (runtime.js:155)
    at runtime.js:165
    at tryCallOne (core.js:37)
    at core.js:123

by looking inside the package I think the issue is with react-native-iaphub trying to parse a response that is not a valid json

try {
      response = await fetchWithRetry(
        `${this.apiUrl}/app/${this.appId}/user/${this.userId}${url}`,
        opts
      );
      text = await response.text();
      json = JSON.parse(text); // <--- the line where the error occurs
    } catch (err) {
      throw this.error(
        `Network error, request to the Iaphub API failed (${err.message})`,
        "network_error",
        {response: text, status: response ? response.status : null}
      );
    }

running on:

"react-native-iap": "5.2.6",
"react-native-iaphub": "^6.4.1",
"react-native": "^0.67.2",

The weird thing is it worked just fine yesterday, so it could totally be a user related error

iaphub commented 1 year ago

Hi @Subalee,

The error should return the request response and status in err.params.response and err.params.status. Could you send us the content?

Thanks

subalee commented 1 year ago

Hey @iaphub sorry for not replying sooner. Not 100% sure if this was the case but I think what caused the issue for me was the react-native-debugger.

I think the issue was that it was intercepting the polyfilled fetch used by react-native-iaphub

Once I turned the debugger off everything started to work again.

I'll close this but if you are interested to reproduce it you could just try out the debugger. Or maybe it was something completely different.