예제 #1
0
파일: api.py 프로젝트: chojar/GlobaLeaks
    def handle_exception(self, e, request):
        """
        handle_exception is a callback that decorators all deferreds in render

        It responds to properly handled GL Exceptions by pushing the error msgs
        to the client and it spools a mail in the case the exception is unknown
        and unhandled.

        @param e: A `Twisted.python.Failure` instance that wraps a `GLException`
                  or a normal `Exception`
        @param request: The `twisted.web.Request`
        """
        if isinstance(e, errors.GLException):
            pass
        elif isinstance(e.value, errors.GLException):
            e = e.value
        else:
            e.tid = request.tid
            e.url = request.client_proto + b'://' + request.hostname + request.uri
            extract_exception_traceback_and_schedule_email(e)
            e = errors.InternalServerError('Unexpected')

        request.setResponseCode(e.status_code)
        request.setHeader(b'content-type', b'application/json')

        response = json.dumps({
            'error_message': e.reason,
            'error_code': e.error_code,
            'arguments': getattr(e, 'arguments', [])
        })

        request.write(response.encode())
예제 #2
0
    def handle_exception(self, e, request):
        """
        handle_exception is a callback that decorators all deferreds in render

        It responds to properly handled GL Exceptions by pushing the error msgs
        to the client and it spools a mail in the case the exception is unknown
        and unhandled.

        :param e: A `Twisted.python.Failure` instance that wraps a `GLException`
                  or a normal `Exception`
        :param request: A `twisted.web.Request`
        """
        if isinstance(e, NoResultFound):
            e = errors.ResourceNotFound()
        elif isinstance(e, errors.GLException):
            pass
        elif isinstance(e.value, errors.GLException):
            e = e.value
        else:
            e.tid = request.tid
            e.url = request.hostname + request.path
            extract_exception_traceback_and_schedule_email(e)
            e = errors.InternalServerError('Unexpected')

        request.setResponseCode(e.status_code)
        request.setHeader(b'content-type', b'application/json')

        response = json.dumps({
            'error_message': e.reason,
            'error_code': e.error_code,
            'arguments': getattr(e, 'arguments', [])
        })

        request.write(response.encode())
예제 #3
0
 def on_error(self, excep):
     log.err("Exception while running %s" % self.name)
     log.exception(excep)
     extract_exception_traceback_and_schedule_email(excep)
예제 #4
0
 def on_error(self, excep):
     error = "Job %s died with runtime %.4f [low: %.4f, high: %.4f]" % \
             (self.name, self.mean_time, self.low_time, self.high_time)
     log.err(error)
     log.exception(excep)
     extract_exception_traceback_and_schedule_email(excep)
예제 #5
0
 def on_error(self, excep):
     log.err("Exception while running %s" % self.name)
     log.exception(excep)
     extract_exception_traceback_and_schedule_email(excep)
예제 #6
0
 def test_extract_exception_traceback_and_schedule_email(self):
     yield self.test_model_count(models.Mail, 0)
     extract_exception_traceback_and_schedule_email(Exception())
     yield self.test_model_count(models.Mail, 1)
     extract_exception_traceback_and_schedule_email(Failure(Exception()))
     yield self.test_model_count(models.Mail, 2)
예제 #7
0
파일: job.py 프로젝트: chojar/GlobaLeaks
 def on_error(self, excep):
     error = "Job %s died with runtime %.4f [low: %.4f, high: %.4f]" % \
             (self.name, self.mean_time, self.low_time, self.high_time)
     log.err(error)
     log.exception(excep)
     extract_exception_traceback_and_schedule_email(excep)