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?
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