Forum Discussion

Scifi_guy's avatar
Scifi_guy
Channel Surfer
10 years ago

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?

3 Replies

  • 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
  • Scifi_guy's avatar
    Scifi_guy
    Channel Surfer
    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