blob: 5b8fb9819748e88754ff1a901f476fd395536a45 [file] [log] [blame]
Akronca9bd982016-12-06 16:59:57 +01001__author__ = 'hanl'
2
3
4class MessageHandler(object):
5 def isError(self, response):
6 pass
7
8 def notifyNext(self, json, notify_func):
9 pass
10
11
12class NotificationHandler(MessageHandler):
13 def __init__(self):
14 pass
15
16 def isError(self, response):
17 try:
18 raw_json = response.json()
19 if raw_json.get('errors') or raw_json.get('error') or raw_json.get('err'):
20 return True
21 except ValueError:
22 if response.status_code != 200:
23 return True
24 return False
25
26 def getMessage(self, response):
27 pass
28
29 def notifyNext(self, json, notify_func):
30 print "having a notification %s" % str(json)
31 if json.get('errors'):
32 for error in json.get("errors"):
33 notify_func(error[1], "danger")
34 elif json.get('error'):
35 if json.get('error_description'):
36 notify_func(json.get('error_description'), "danger")
37 else:
38 notify_func(json.get('error'), "danger")
39 elif json.get('err'):
40 notify_func(json.get('errstr'), "danger")
41 return None
42
43 def getLocalized(self, code):
44 # return _("status_" + str(code))
45 return "this is a default message"
46