示例#1
0
 def __bool__(self):
     status_code = self.response.status_code
     if status_code == 200:
         return True
     else:
         logger.error(f'Status code: {status_code}'
                      f'Response: {self.response}')
示例#2
0
 def _log_error(self):
     try:
         if 'error' not in self.content:
             return
         try:
             logger.warning(WARNING_MESSAGE[self.content['error']])
         except KeyError:
             logger.error(self)
     except KeyError:
         pass
示例#3
0
 def serve(self, data):
     if 'challenge' in data:
         return self._response_challenge(data['challenge'])
     else:
         try:
             self._handle_event(data)
         except Exception:
             logger.error(traceback.format_exc())
         return self._response_code(200)
     return self._response_code(404)
示例#4
0
def slack_https():
    logger.debug(f'Headers={str(request.headers)}')
    data = request.get_json()
    if data is None:
        logger.error(f'Slack event server got none json message.'
                     f'args: {request.args}, data: {request.data}')
        return 'OK'
    thread = Process(target=process_data, args=(data, ))
    thread.start()
    logger.info(f'Responding to slack with OK')
    return slack_event_server._response_code(200)
示例#5
0
 def wrapper(self, event):
     if 'subscribed_channels' not in db:
         return False
     try:
         if 'item' in event:
             channel = event['item']['channel']
         else:
             channel = event['channel']
     except KeyError:
         logger.error('this event does not contain channel information'
                      ' or it does not relate to channel')
         return False
     if channel not in db['subscribed_channels']:
         return False
     return func(self, event)
示例#6
0
 def __bool__(self):
     if self.content['ok']:
         return True
     else:
         logger.error(f'slack api error: {self.content["error"]}')
         return False