Exemple #1
0
 def process_response(self, request, response):
     try:
         return self._process_response(request, response)
     except Exception, e:
         # Don't spam if the exception has a status code lower than 500
         isISE = (getattr(e, 'status', 500) >= 500)
         return handler.handleException(request, e,
             doEmail=isISE, doTraceback=isISE)
Exemple #2
0
 def process_response(self, request, response):
     try:
         return self._process_response(request, response)
     except Exception, e:
         return handler.handleException(request, e)
Exemple #3
0
 def process_request(self, request):
     try:
         return self._process_request(request)
     except Exception, e:
         return handler.handleException(request, e)
Exemple #4
0
    def process_exception(self, request, exception):

        # email will only be sent if this is True AND
        # we don't return early from this function
        doEmail=True

        if isinstance(exception, PermissionDenied):
            # TODO: factor out duplication
            code = 403
            fault = models.Fault(code=code, message=str(exception))
            response = HttpResponse(status=code, content_type='text/xml')
            response.content = fault.to_xml(request)
            log.error(str(exception))
            self._logFailure(request, code, str(exception))
            return response

        if isinstance(exception, core_exc.ObjectDoesNotExist):
            # django not found in a get/delete is usually a bad URL
            # in a PUT/POST, it's usually trying to insert or
            # mangle something in a way that does not align with the DB
            code=404
            if request.method not in [ 'GET', 'DELETE' ]:
                code = 400

            # log full details, but don't present to user, in case
            # XML submitted was rather confusing and we can't tell what
            # was not found on the lookup, which could happen
            # anywhere in the call chain
            log.error(traceback.format_exc())

            fault = models.Fault(code=code, message=str(exception))
            response = HttpResponse(status=code, content_type='text/xml')
            response.content = fault.to_xml(request)
            log.error(str(exception))
            self._logFailure(request, code, str(exception))
            return response

        if isinstance(exception, errors.RbuilderError):
            tbStr = getattr(exception, 'traceback', None)
            status = getattr(exception.__class__, 'status', 500)
            fault = models.Fault(code=status, message=str(exception), traceback=tbStr)
            response = HttpResponse(status=status, content_type='text/xml')
            try:
                for k, v in exception.iterheaders(request):
                    response[k] = v
            except AttributeError:
                pass
            response.content = fault.to_xml(request)
            log.error(str(exception))
            self._logFailure(request, status, str(exception))
            return response

        if isinstance(exception, IntegrityError):
            # IntegrityError is a bug but right now we're using it as a crutch
            # (bad practice, should catch and map to reasonable errors)
            # so do not log tracebacks when there's an uncaught conflict.
            # user will still get an ISE w/ details
            self._logFailure(request, 'IntegrityError', str(exception))
            return handler.handleException(request, exception,
                    doTraceback=False, doEmail=False)

        if isinstance(exception, ierrors.IncompatibleEvent):
            doEmail = False

        return handler.handleException(request, exception, doEmail=doEmail)