fix: network call timeout (#38953)

Summary:
This PR is a continuation of this https://github.com/facebook/react-native/pull/29471. All context you can find here:

https://github.com/axios/axios/issues/2073#issuecomment-1050917487
https://github.com/axios/axios/issues/2073#issuecomment-1674817612

## Changelog:

[ANDROID] [FIXED] - change `connectTimeout` to `callTimeout` in OKHttp client

Pull Request resolved: https://github.com/facebook/react-native/pull/38953

Test Plan:
- Throttle internet connection (You can use GSM one)

```
import axios from "axios";

axios.get('https://jsonplaceholder.typicode.com/users', {
  timeout: 5000
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  if (error.code === 'ECONNABORTED') {
    console.log('Request timed out');
  } else {
    console.log(error.message);
  }
});
```

**Expected result**

`Request timed out` should be visible in a console

**Videos**

Before

https://github.com/facebook/react-native/assets/12766071/03a3d666-6a27-4d67-bc68-6bcf6e908e19

After

https://github.com/facebook/react-native/assets/12766071/2650d02d-640c-43fe-b1e8-baeac78870f2

**Example URL**

Branch:
https://github.com/troZee/react-native/tree/fix/network-timeout-example

Commit:
https://github.com/troZee/react-native/commit/e255e1a423143c4bd4f3e37656a56ba2ecbbf3e2

Reviewed By: mdvacca

Differential Revision: D48414884

Pulled By: NickGerleman

fbshipit-source-id: 86324601f7459c154b5fc879f8b773df4901f6e0
This commit is contained in:
troZee
2023-09-10 00:45:49 -07:00
committed by Facebook GitHub Bot
parent 17ecae9ce7
commit e00f2445d2
@@ -343,8 +343,8 @@ public final class NetworkingModule extends NativeNetworkingAndroidSpec {
// client and set the timeout explicitly on the clone. This is cheap as everything else is
// shared under the hood.
// See https://github.com/square/okhttp/wiki/Recipes#per-call-configuration for more information
if (timeout != mClient.connectTimeoutMillis()) {
clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
if (timeout != mClient.callTimeoutMillis()) {
clientBuilder.callTimeout(timeout, TimeUnit.MILLISECONDS);
}
OkHttpClient client = clientBuilder.build();