Merge pull request #99 from madsmtm/message_error_handling

Added error handling when sending messages
This commit is contained in:
Taehoon Kim
2017-02-07 00:32:43 +09:00
committed by GitHub

View File

@@ -413,10 +413,21 @@ class Client(object):
data["sticker_id"] = sticker data["sticker_id"] = sticker
r = self._post(SendURL, data) r = self._post(SendURL, data)
if not r.ok:
return False
if isinstance(r._content, str) is False:
r._content = r._content.decode(facebookEncoding)
j = get_json(r._content)
if 'error' in j:
# 'errorDescription' is in the users own language!
log.warning('Error #{} when sending message: {}'.format(j['error'], j['errorDescription']))
return False
log.debug("Sending {}".format(r)) log.debug("Sending {}".format(r))
log.debug("With data {}".format(data)) log.debug("With data {}".format(data))
return r.ok return True
def sendRemoteImage(self, recipient_id, message=None, message_type='user', image=''): def sendRemoteImage(self, recipient_id, message=None, message_type='user', image=''):
"""Send an image from a URL """Send an image from a URL