WebInputStream::getStatusCode() - default value


#1

If I’m offline and do the following :

WebInputStream wis ({ "https://juce.com/" }, false);
int status = wis.getStatusCode();

I got the status code 0, which is not an official status code.
should it be initialized to 404 rather than 0?


#2

But a 404 would imply it is a response from the server.

IMHO you should use WebInputStream::isError() before evaluating the status code, especially as the docs state “Returns the status code returned by the http server.”


#3

ah yes, that makes sense!

(worth mentioning that WebInputStream::isError() does not call connect() if there is no established connection already (unlike WebInputStream.getStatusCode())


#4

Ah right, forgot about the “convenience connect” in getStatusCode().

So yes, you will have to call connect manually before you can check isError(). Thanks for pointing that out.