I am trying to catch a 404 status in a HTMLViewer. The docs list the Error event with parameters ErrorNumber, ErrorMessage, which would be what I need. However the actual event as implemented in the code shows “Error as RuntimeException” as the only parameter. Moreover, it is not triggered by a 404 status.
Is there a way to read the http status of the loaded page?
I guess the documentation needs to be updated anyway.
Unfortunately I don’t know of a way to retrieve the status code via the DesktopHTMLViewer. HTTP status isn’t available via Javascript. We should have a feature request for this.
The best you could probably do is to verify each page with a subsequent URLConnection.
Sub DocumentComplete(url as String) Handles DocumentComplete
var c as new UrlConnection
Try
Call c.SendSync("GET", url, 10)
Catch e as RuntimeException
End Try
if c.HTTPStatusCode = 404 then
MessageBox "404 Error"
end if
End Sub
I realize this is imperfect with dynamic pages, logins and such, but it’s all I could come up with.
Maybe a feature request for an HTTPException to the HTMLViewer error event would be useful.
This would allow for a good an easy way to differentiate between exceptions and handle such accordingly.
I was under the impression that there was a NSHTTPURLResponse which you could pull a status code from. It’s been a long time since I dug into it though.