Skip to content

Commit 30d8931

Browse files
authored
fixed fetch abort on timedout (react-native-netinfo#709)
1 parent 736138c commit 30d8931

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/internal/internetReachability.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export default class InternetReachability {
7979

8080
// Create promise that will reject after the request timeout has been reached
8181
let timeoutHandle: ReturnType<typeof setTimeout>;
82-
const timeoutPromise = new Promise<Response>((): void => {
82+
const timeoutPromise = new Promise<Response>((_, reject): void => {
8383
timeoutHandle = setTimeout(
84-
(): void => controller.abort('timedout'),
84+
(): void => reject('timedout'),
8585
this._configuration.reachabilityRequestTimeout,
8686
);
8787
});
@@ -120,6 +120,10 @@ export default class InternetReachability {
120120
if ('canceled' === error) {
121121
controller.abort();
122122
} else {
123+
if ('timedout' === error) {
124+
controller.abort();
125+
}
126+
123127
this._setIsInternetReachable(false);
124128
this._currentTimeoutHandle = setTimeout(
125129
this._checkInternetReachability,

0 commit comments

Comments
 (0)