code: private static void checkResponseCode(URLConnection uc) throws IOException {
          if (uc instanceof HttpURLConnection) {
              HttpURLConnection httpConnection = (HttpURLConnection) uc;
              int rc = httpConnection.getResponseCode();
              if (rc != HttpURLConnection.HTTP_OK && rc != HttpURLConnection.HTTP_MOVED_TEMP) {
                  throw new IOException();
              }
          }
      }
docs: If URLConnection is an HTTP connection, check that the response code is HTTP_OK
  
  @param uc the URLConnection
  @throws IOException if the URLConnection is an HttpURLConnection and the response code is not HTTP_OK (200) or HTTP_MOVED_TEMP (302)