Closed farski closed 9 years ago
I don't care much for XML either :). But seriously, can you give more details on how the widget breaks - it doesn't update anymore?
If I add an empty try/catch I usually get 9/25/14 1:07:06.322 PM Übersicht[446]: error in widget mbta_85in-school-coffee: unexpected (
, if I have anything in the try it's similar, but depends on what the code is actually doing (eg unexpected =
, etc)
could you paste your try/catch block here? I just tried using one and it works fine, so maybe it is just a syntax mistake
update: (output, element) ->
try {
json = JSON.parse(output)
predictedArrival = json['mode'][0]['route'][0]['direction'][0]['trip'][0]['pre_dt']
t = new Date(predictedArrival* 1000)
$(element).find('h3').text(@getHHMMString(t) )
} catch(e) {
}
hey and sorry for the late reply! You are using the javascript syntax, which is slightly different. This is the correct CoffeeScript syntax is:
update: (output, element) ->
try
json = JSON.parse(output)
predictedArrival = json['mode'][0]['route'][0]['direction'][0]['trip'][0]['pre_dt']
t = new Date(predictedArrival* 1000)
$(element).find('h3').text(@getHHMMString(t) )
catch e
# do nothing
I'm
JSON.parse
ing an API that doesn't have a very good data policy; they return XML rather than JSON in a lot of situations. I never care about the XML, so I just need a way of avoiding parsing errors, but doing a try/catch inside ofupdate
seems to break the widget. Is there a better way to handle things like this?