2

I'm new to Roku coding and I was wondering if there is a simple Function (non-Task Node) that I can use to check and see if a URL is valid or not and then just return a Yay or Nay so I can check a second URL? Thank you

matrixebiz
  • 97
  • 2
  • 10

3 Answers3

0

You can find what you are looking for here: roSystemLog

You also have a good sample code in this link that you can follow.

U.Mitic
  • 744
  • 1
  • 6
  • 14
  • Hello, thanks for the response but that looks way over my head. I don't understand it :( Do I just call it like : showVideoScreenWithLogging(URL)? what will the return be? – matrixebiz Oct 15 '17 at 19:34
  • Hey, U.Mitic Any Exception Handling Statement available in Roku? Like try-catch or any else? – Nikunj Chaklasiya Dec 19 '19 at 13:41
0

You could try running Eval() on the url call, and check for a 400-level error. If the error is present then proceed to another Eval() call on the next url you want, and so on until you get a URL you can break out of the function with. Eval() will test the code, and if no errors will proceed, but if it throws a runtime error it will just stop THAT code execution and not crash the application. It's a pretty decent ad-hoc exception handler. See here: https://sdkdocs.roku.com/display/sdkdoc/Runtime+Functions#RuntimeFunctions-Eval(codeasString)asDynamic

0

You can make a request to the URL with an roTransfer, and check for errors. In this example, I'm using a GetHead(), since all you need to do is check for validity.

' given a 404 URL
url = "http://example.com/404"

' request HEAD for the URL
urlTransfer = CreateObject("roUrlTransfer")
urlTransfer.setUrl(url)
urlEvent = urlTransfer.head()
if urlEvent <> Invalid
    responseCode = urlEvent.getResponseCode()
    if responseCode >= 200 and responseCode < 300
        print "success"
    else
        print "fail with code " + Stri(responseCode)
    end if
else
    print "transfer failed"
end if
Jess Bowers
  • 2,846
  • 1
  • 22
  • 42
  • Hello, I'll try this but I think I tried this already and I get a Debug error about roUrlTransfer cannot be used as a Task node due to the file it's being run in. I need to have the check done as a simple function. I'll let you know. – matrixebiz Feb 08 '18 at 15:15