Added util function to print twitter errors
authorLukas Pohlreich <pohlreichlukas@gmail.com>
Wed, 22 Oct 2014 10:17:21 +0000 (12:17 +0200)
committerLukas Pohlreich <pohlreichlukas@gmail.com>
Wed, 22 Oct 2014 10:17:21 +0000 (12:17 +0200)
rainbowstream/util.py [new file with mode: 0644]

diff --git a/rainbowstream/util.py b/rainbowstream/util.py
new file mode 100644 (file)
index 0000000..232845c
--- /dev/null
@@ -0,0 +1,16 @@
+import json
+
+from twitter.util import printNicely
+
+from .colors import magenta
+
+
+def printTwitterErrors(twitterException):
+    try:
+        loadedJson = json.loads(twitterException.response_data)
+        for m in loadedJson.get('errors', dict()):
+            printNicely(
+                magenta("Error " + str(m.get('code')) + ": " + m.get('message')))
+    except ValueError:
+        printNicely(
+                magenta( "Error: " + twitterException.response_data))