def _handle_request_exception(self, e): # If something goes wrong at one side of interaction, # closes the other side as well (desktop / app) _partner = None _interaction = mn.get_Interaction(self.RequestID) if _interaction and _interaction._source: _interaction._completed = False if _interaction._source == self: _partner = _interaction._destination else: _partner = _interaction._source #super(IWP_Handler, self)._handle_request_exception(e) if isinstance(e, HTTPError): if e.log_message: format = "%d %s: " + e.log_message args = [e.status_code, self._request_summary()] + list(e.args) gen_log.warning(format, *args) if e.status_code not in tornado.httputil.responses and not e.reason: gen_log.error("Bad HTTP status code: %d", e.status_code) self.send_error(500, exc_info=sys.exc_info()) else: self.send_error(e.status_code, exc_info=sys.exc_info()) elif isinstance(e, StreamClosedError): if _partner: IOLoop.instance().add_callback(_partner.send_error, 503, exc_info=sys.exc_info()) self.send_error(503, exc_info=sys.exc_info()) else: self.send_error(500, exc_info=sys.exc_info()) elif isinstance(e, http.StreamClosedWarning): app_log.warning('%s write to closed stream', self._request_summary()) if _partner: IOLoop.instance().add_callback(_partner.send_error, 503, exc_info=sys.exc_info()) self.send_error(503, exc_info=sys.exc_info()) else: self.send_error(500, exc_info=sys.exc_info()) pass else: app_log.error("Uncaught exception %s\n%r", self._request_summary(), self.request, exc_info=True) self.send_error(500, exc_info=sys.exc_info())
def process_reply(self): # Replies: Mobile App <- Desktop _interaction = mn.get_Interaction(self.RequestID, validateID=self.ProductID) if _interaction and not _interaction.client._closed( ) and not _interaction.agent: _interaction._set_agent(self) _interaction(self, _interaction.client, source_finish=True) elif _interaction and _interaction.agent: self.request.connection.no_keep_alive = True self.send_error(501, exc_info=(HTTPError, HTTPError(501, 'RequestID is being replied'))) else: self.request.connection.no_keep_alive = True self.send_error(502, exc_info=(HTTPError, HTTPError(502, 'No client to reply')))
def on_finish(self): _interaction = mn.get_Interaction(self.RequestID, remove=True) if _interaction: _interaction._clear(self.request.request_time() * 1000)
def on_finish(self): _interaction = mn.get_Interaction(self.RequestID) if _interaction: _interaction._clear_transaction()