FAQ  •  Register  •  Login

URL Errors - 404 Unknown & 500 Timeout

<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sat Mar 03, 2012 5:21 pm

URL Errors - 404 Unknown & 500 Timeout

I'm a newbie with groovy and java.

When getting a URL
  Code:
            String videohtml = new URL(videoUrl).getText()

I can first test to ensure it exists and avoid 404 errors using this code
  Code:
   Boolean URLExists(URL fileURL){
      if(((HttpURLConnection) fileURL.openConnection()).getResponseCode() == 404){
         return false
      }
      return true
   }


But how do I avoid or catch 500 errors like this
  Code:
Caught: java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
        at HaHaSport.extractItems(HaHaSport.groovytest.txt:190)
        at HaHaSport$extractItems.call(Unknown Source)
        at HaHaSport.main(HaHaSport.groovytest.txt:1320)


I'd like to catch them and retry rather than get an exception.
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Sat Mar 03, 2012 9:15 pm

Re: URL Errors - 404 Unknown & 500 Timeout

you can just wrap the code in try - catch block (http://groovy.codehaus.org/JN3035-Exceptions) and catch the timeout exception.

Not sure if re-try os the way to go though, depends if there is a chance it'll work the second time around, otherwise it'll take ages to add the items

Return to Plugin development

Who is online

Users browsing this forum: No registered users and 17 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.