Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Scifi_guy
Channel Surfer

404 error

I get the url of an image from an api call. Well it turns out there is no image at that url. Brightscript doesn't error out, it keeps running but now everything is screwed up. So, is there anyway to test for a 404? Anyway to test image size before displaying it? Any suggestions at all?
0 Kudos
3 REPLIES 3
Veeta
Visitor

Re: 404 error

You should use the roSystemLog http://sdkdocs.roku.com/display/sdkdoc/roSystemLog to capture the 404 result, unless you think that it's something that will happen often.

If you want to be more proactive rather than reactive, use http://sdkdocs.roku.com/display/sdkdoc/ifUrlTransfer#ifUrlTransfer-HeadasDynamic to do HEAD on the URL. This will give you the 404 if it's missing, and if it's found it will not attempt to download the file.
0 Kudos
RokuMarkn
Visitor

Re: 404 error

You didn't say which API you're using, but roUrlTransfer.GetToFile returns the HTTP status code, and the Async methods give the status code in the roUrlEvent.

--Mark
0 Kudos
Scifi_guy
Channel Surfer

Re: 404 error

Function check(thisurl) as string
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
request.SetUrl(thisurl)
if (request.AsyncGetToString())
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
print"good"
return "good"

elseif (code =400 or code=404)
print("image not found")
return "bad"
else
print"error"; code
return "generic bad code"

endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid
End Function
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.