From 9bf83fd933b61fbdc025636621ba1ed7c505d260 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Wed, 9 Oct 2013 14:39:45 -0400 Subject: [PATCH] Don't mask TwythonStreamer exceptions Exceptions in handlers or on_success which subclass ValueError would previously be caught and reported as a JSON decoding problem, and on_error() would be called (with status_code=200). --- twython/streaming/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/twython/streaming/api.py b/twython/streaming/api.py index 6fa247e..c814acb 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -139,14 +139,15 @@ class TwythonStreamer(object): if is_py3: line = line.decode('utf-8') data = json.loads(line) + except ValueError: # pragma: no cover + self.on_error(response.status_code, 'Unable to decode response, not valid JSON.') + else: if self.on_success(data): # pragma: no cover for message_type in self.handlers: if message_type in data: handler = getattr(self, 'on_' + message_type, None) if handler and callable(handler) and not handler(data.get(message_type)): break - except ValueError: # pragma: no cover - self.on_error(response.status_code, 'Unable to decode response, not valid JSON.') response.close()