title: groovy,Jsoup, get status code
body: <p>I hope someone can help me with this as I have been searching for it but didn't find anything working.</p>
  
  <p>I am connecting to a number of urls from a list and everything works fine but then I started getting a 404 error on some hence now I want to catch the error so that the program doesn't terminate and keeps going through the list urls.</p>
  
  <p>This is the error I got</p>
  
  <pre><code>org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=http:nameofthesite
  </code></pre>
  
  <p>I am using Jsoup.connect and the error is caused in this line of code</p>
  
  <pre><code>    Document doc= Jsoup.connect(countryUrl[i2]).timeout(10*1000)                      
      .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")
      .get();
  </code></pre>
  
  <p>How can I change the code so that I can get the status code.
  I've tried Connection.response (something I found on this site as a solution for this sort of problem) but I was getting casting error</p>
  
  <pre><code> Connection.response  response= Jsoup.connect(countryUrl[i2]).timeout(10*1000)                      
              .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")
              .execute();
              int statusCode = response.statusCode();
              if(statusCode==200){
  </code></pre>
  
  <p>but I get the following error </p>
  
  <pre><code>groovy.lang.MissingMethodException: No signature of method: static org.jsoup.Connection.response() is applicable for argument types: (org.jsoup.helper.HttpConnection$Response) values: [org.jsoup.helper.HttpConnection$Response@c7325ae]
  Possible solutions: respondsTo(java.lang.String), respondsTo(java.lang.String, [Ljava.lang.Object;)
  </code></pre>
  
  <p>any help will be appreciated, thanks.</p>