Last active
November 5, 2019 10:18
-
-
Save pradhul-dev/89266a9e113cdebaf8d6ec755e1e3dd6 to your computer and use it in GitHub Desktop.
React native's Netinfo gives connectivity status but not actually tells weather any URL is reachable or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TimeoutError } from 'rxjs' | |
import { ajax } from 'rxjs/ajax' | |
import { catchError, map, timeout } from 'rxjs/operators' | |
/** | |
* Netinfo method for checking internet connection won't tell weather the internet is actually accessible or not | |
* make a test API call to verify | |
*/ | |
export function isInternetAvailable() { | |
ajax('https://google.com').pipe( | |
timeout(100), | |
map(userResponse => console.log('Got response', userResponse)), | |
catchError(err => { | |
console.log('An Error occured', err) | |
if (err instanceof TimeoutError) { | |
console.log('Request Timeout!!') | |
} | |
return of(err) | |
}), | |
).subscribe() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment