Added code to check for internet connection before executing api request