Added checking network connection before calling the API.