Best Way To Detect Missing JSON? #555
Unanswered
espruino-discuss
asked this question in
JavaScript
Replies: 2 comments
-
Posted at 2016-04-24 by Wilberforce 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. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Posted at 2016-04-25 by @gfwilliams I'd suggest:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-04-24 by MrTimcakes
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?
Beta Was this translation helpful? Give feedback.
All reactions