Example #1
0
 def _handle_request_exception(self, e):
     """
     Overridden to pass on the exception object to send_error.  Otherwise,
     should track superclass version.
     """
     if isinstance(e, HTTPError):
         if e.log_message:  # pragma: no cover
             format = "%d %s: " + e.log_message
             args = [e.status_code, self._request_summary()] + list(e.args)
             logging.warning(format, *args)
         if e.status_code not in httplib.responses:
             logging.error("Bad HTTP status code: %d", e.status_code)
             self.send_error(500, exc_info=sys.exc_info(), exception=e)
         else:  # pragma: no cover
             self.send_error(e.status_code,
                             exc_info=sys.exc_info(),
                             exception=e)
     else:
         logging.error("Uncaught exception %s\n%r",
                       self._request_summary(),
                       self.request,
                       exc_info=True)
         utils.write_core_file(settings.LOG_FILE_PREFIX,
                               traceback.format_exc())
         self.send_error(500, exc_info=sys.exc_info(), exception=e)
Example #2
0
    def _handle_request_exception(self, e):
        """
        Overridden to intercept the exception object and pass to send_error
        """
        err_traceback = traceback.format_exc()
        orig_e = e
        if e.__class__ == Failure:
            err_traceback = e.getTraceback()
            e = e.value

        if type(e) == HTTPError:
            if e.log_message:
                format = "%d %s: " + e.log_message
                args = [e.status_code, self._request_summary()] + list(e.args)
                pdlogs.API_HTTPERROR.log(error=format % tuple(args))
                _log.warning(format, *args)
            if e.status_code not in httplib.responses:
                pdlogs.API_HTTPERROR.log(
                    error="bad status code %d for %s" %
                    (e.status_code, self._request_summary()))
                _log.warning("Bad HTTP status code: %d", e.status_code)
                cyclone.web.RequestHandler._handle_request_exception(self, e)
            else:
                _log.debug("Sending HTTP error: %d", e.status_code)
                self.send_error(e.status_code,
                                httplib.responses[e.status_code],
                                exception=e)
        elif type(e) == HSSOverloaded:
            _log.error("Translating HSS overload error into a 502 status code",
                       type(e))
            self.send_error(502)
        elif type(e) in [
                HSSStillConnecting, HSSConnectionLost, TimeoutError,
                CassandraTimeout
        ]:
            _log.error("Translating internal %s error into a 503 status code",
                       type(e))
            self.send_error(503)
        elif type(e) == UserNotIdentifiable:
            _log.error(
                "Translating user not identifiable error into a 404 status code",
                type(e))
            self.send_error(404)
        elif type(e) == UserNotAuthorized:
            _log.error(
                "Translating user not authorized error into a 403 status code",
                type(e))
            self.send_error(403)
        else:
            pdlogs.API_UNCAUGHT_EXCEPTION.log(
                exception="%s - %s" % (repr(e), self._request_summary()))
            _log.error("Uncaught exception %s\n%r", self._request_summary(),
                       self.request)
            _log.error("Exception: %s" % repr(e))
            _log.error(err_traceback)
            utils.write_core_file(settings.LOG_FILE_PREFIX,
                                  traceback.format_exc())
            cyclone.web.RequestHandler._handle_request_exception(self, orig_e)
Example #3
0
 def onAnswer(self, peer, answer):
     try:
         key = self.request_hash(answer)
         if key in self._pending_responses:
             _log.debug("Executing callbacks for pending requests %s" % hash(key))
             for deferred in self._pending_responses.pop(key):
                 deferred.callback(answer)
     except:
         utils.write_core_file(settings.LOG_FILE_PREFIX,
                               traceback.format_exc())
         _log.exception("Caught exception while processing DIAMETER response")
Example #4
0
 def onRequest(self, peer, request):
     try:
         if self.cx.isCommand(request, "Push-Profile"):
             yield self.onPushProfileRequest(peer, request)
         elif self.cx.isCommand(request, "Registration-Termination"):
             yield self.onRegistrationTerminationRequest(peer, request)
         else:
             answer = peer.stack.createAnswer(request, resultcodes.DIAMETER_COMMAND_UNSUPPORTED)
             peer.stack.sendByPeer(peer, answer)
     except:
         # We must catch and handle any exception here, as otherwise it will
         # propagate up to the Diameter stack and kill it.
         utils.write_core_file(settings.LOG_FILE_PREFIX,
                               traceback.format_exc())
         _log.exception("Caught exception while processing DIAMETER request")
Example #5
0
    def _handle_request_exception(self, e):
        """
        Overridden to intercept the exception object and pass to send_error
        """
        err_traceback = traceback.format_exc()
        orig_e = e
        if e.__class__ == Failure:
            err_traceback = e.getTraceback()
            e = e.value

        if type(e) == HTTPError:
            if e.log_message:
                format = "%d %s: " + e.log_message
                args = [e.status_code, self._request_summary()] + list(e.args)
                pdlogs.API_HTTPERROR.log(error=format % tuple(args))
                _log.warning(format, *args)
            if e.status_code not in httplib.responses:
                pdlogs.API_HTTPERROR.log(error="bad status code %d for %s" % (e.status_code, self._request_summary()))
                _log.warning("Bad HTTP status code: %d", e.status_code)
                cyclone.web.RequestHandler._handle_request_exception(self, e)
            else:
                _log.debug("Sending HTTP error: %d", e.status_code)
                self.send_error(e.status_code, httplib.responses[e.status_code], exception=e)
        elif type(e) == HSSOverloaded:
                _log.error("Translating HSS overload error into a 502 status code", type(e))
                self.send_error(502)
        elif type(e) in [HSSStillConnecting, HSSConnectionLost, TimeoutError, CassandraTimeout]:
                _log.error("Translating internal %s error into a 503 status code", type(e))
                self.send_error(503)
        elif type(e) == UserNotIdentifiable:
                _log.error("Translating user not identifiable error into a 404 status code", type(e))
                self.send_error(404)
        elif type(e) == UserNotAuthorized:
                _log.error("Translating user not authorized error into a 403 status code", type(e))
                self.send_error(403)
        else:
            pdlogs.API_UNCAUGHT_EXCEPTION.log(exception="%s - %s" % (repr(e), self._request_summary()))
            _log.error("Uncaught exception %s\n%r", self._request_summary(), self.request)
            _log.error("Exception: %s" % repr(e))
            _log.error(err_traceback)
            utils.write_core_file(settings.LOG_FILE_PREFIX, traceback.format_exc())
            cyclone.web.RequestHandler._handle_request_exception(self, orig_e)
Example #6
0
 def _handle_request_exception(self, e):
     """
     Overridden to pass on the exception object to send_error.  Otherwise,
     should track superclass version.
     """
     if isinstance(e, HTTPError):
         if e.log_message:
             format = "%d %s: " + e.log_message
             args = [e.status_code, self._request_summary()] + list(e.args)
             logging.warning(format, *args)
         if e.status_code not in httplib.responses:
             logging.error("Bad HTTP status code: %d", e.status_code)
             self.send_error(500, exc_info=sys.exc_info(), exception=e)
         else:
             self.send_error(e.status_code, exc_info=sys.exc_info(), exception=e)
     else:
         logging.error("Uncaught exception %s\n%r", self._request_summary(),
                       self.request, exc_info=True)
         utils.write_core_file(settings.LOG_FILE_PREFIX, traceback.format_exc())
         self.send_error(500, exc_info=sys.exc_info(), exception=e)