-
• #2
You should be able to look at the http status code, 200 is ok, anything in the 400 or 500 range is an error.
If you post your code as an example suggestions can be made.
-
• #3
I'd suggest:
var json; try { json = JSON.parse(data); } catch (e) {} if (json && "Hostname" in json) { ... } else { // no data }
I'm parsing some JSON data from a web-server but in-case the server is down or returns something unexpected I want my code to do something safe. I tried checking if the data was undefined but that produces the error:
So next I tried data.hasOwnProperty but this isn't implemented in Espruino's implementation of JSON :/
So I resorted to try catch which works just fine. Was this the right thing to do or should Espruino have some sort of has for JSON?