From: Ed Page Date: Sat, 18 Dec 2010 15:07:11 +0000 (-0600) Subject: Working around a bug for some and providing more helpful error message for others X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=0c5b4724b922bbcb9fc5d4258d78df1ee1b634a3;hp=da26e28b58d9f50cd77f3c7fe41925a1579826ab Working around a bug for some and providing more helpful error message for others --- diff --git a/src/gvoice/backend.py b/src/gvoice/backend.py index 7950c65..9151954 100755 --- a/src/gvoice/backend.py +++ b/src/gvoice/backend.py @@ -697,7 +697,11 @@ class GVoiceBackend(object): message = Message() message.body = messageParts message.whoFrom = conv.name - message.when = conv.time.strftime("%I:%M %p") + try: + message.when = conv.time.strftime("%I:%M %p") + except ValueError: + _moduleLogger.exception("Confusing time provided: %r" % conv.time) + message.when = "Unknown" conv.messages = (message, ) yield conv @@ -787,9 +791,27 @@ class GVoiceBackend(object): def _parse_with_validation(self, page): json = parse_json(page) - validate_response(json) + self._validate_response(json) return json + def _validate_response(self, response): + """ + Validates that the JSON response is A-OK + """ + try: + assert response is not None, "Response not provided" + assert 'ok' in response, "Response lacks status" + assert response['ok'], "Response not good" + except AssertionError: + try: + if response["data"]["code"] == 20: + raise RuntimeError( +"""Ambiguous error 20 returned by Google Voice. +Please verify you have configured your callback number (currently "%s"). If it is configured some other suspected causes are: non-verified callback numbers, and Gizmo5 callback numbers.""" % self._callbackNumber) + except KeyError: + pass + raise RuntimeError('There was a problem with GV: %s' % response) + _UNESCAPE_ENTITIES = { """: '"', @@ -891,18 +913,6 @@ def extract_payload(flatXml): return jsonTree, flatHtml -def validate_response(response): - """ - Validates that the JSON response is A-OK - """ - try: - assert response is not None - assert 'ok' in response - assert response['ok'] - except AssertionError: - raise RuntimeError('There was a problem with GV: %s' % response) - - def guess_phone_type(number): if number.startswith("747") or number.startswith("1747") or number.startswith("+1747"): return GVoiceBackend.PHONE_TYPE_GIZMO