title: Check for Internet connection from application
body: <p>I need to check if the user is connected to internet before I can proceed.</p>
  
  <p>I am hitting the endpoint using HttpClient as follows:</p>
  
  <pre><code>client := &amp;http.Client{}
  req, _ := http.NewRequest("GET", url, nil)
  req.SetBasicAuth(username, password)
  res, err := client.Do(req)
  
  if err != nil {
      fmt.Println(err)
      ui.Failed("Check your internet connection")
  }
  </code></pre>
  
  <p>1) I need to show clear messages to the user if the user is not connected to the internet in this case, display "Please check your internet connection"</p>
  
  <p>2) In case the server is not responding, and receives 504 bad gateway,
  display "504 Bad gateway"</p>
  
  <p>Can someone help how to proceed and distinguish between these two scenarios and I would like to display only simple messages and not the entire error messages received from the server.</p>