3

My app is crashing hard when doing certain API calls, and I narrowed it down to this point:

  • it's not an HTTP vs HTTPS thing
  • I eventually used two different mock APIs, and to my suprise, one worked, the other didn't. Both are basically the same, see snippet below
  • same behavior on both WIFI or cellular network
  • same issue in axios instead of fetch
  • the catch block is invoked with a nondescript network error, but then the app still crashes hard

Environment: Android 10 (actual device), RN 0.61.5

Both calls below just do a simple HTTP GET which results in a JSON snippet being returned. One works, the other causes a hard crash.

async foo() {
    try {

        // this endpoint CRASHES my app
        const r = await fetch("http://jsonplaceholder.typicode.com/todos/1");
        
        // this endpoint works just fine
        //const r = await fetch("http://echo.jsontest.com/key/value/one/two");

    } catch(e) {
        console.log("Invoked, but the app still crashes hard right after");
    }
}
2
  • Please tell the solution for the issue. Commented Sep 5, 2020 at 18:06
  • I posted my fix as an answer @TanviAgarwal - Commented Sep 7, 2020 at 7:51

2 Answers 2

1

Ok, I found a hint in Logcat - it appears that using OkHttp3 is causing some sort of versioning conflict that only manifests in one of the responses (maybe due to CORS headers, but that's pure, unfounded speculation ;).

My fix was to change my dependency on OkHttp3 in build.gradle from

implementation "com.squareup.okhttp3:okhttp:4.7.2"

to

api(platform("com.squareup.okhttp3:okhttp-bom:4.7.2"))
api("com.squareup.okhttp3:okhttp")
api("com.squareup.okhttp3:logging-interceptor")
Sign up to request clarification or add additional context in comments.

Comments

0

Try adding a timeout to the config in axios

private axios: Axios;
private config: AxiosRequestConfig = {
    baseURL: 'http://192.168.10.18:8000/api',
    headers: {
        'Content-Type': 'application/json'
    },
    timeout: 5000
}
constructor() {
    this.axios = new Axios(this.config);
}

I had the same issue, axios request was crashing the application. No logs on the console or anything. Even tried resolving by the answer accepted but didn't work.

Logcat did help in understanding the issue that null was being passed in Double Data type in java. I thought maybe some animation was we were using was causing this issue, but looks like null is being passed via axios to some library like okhttp for HTTP request.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.