Esempio n. 1
0
 def process_exception(self, request, exception):
     """If an exception occurs, rollback the current transaction
     if it exists.
     """
     sentry_exception_handler(request=request)
     transaction_teardown_request(error=True)
     return None
Esempio n. 2
0
 def process_exception(self, request, exc):
     sentry_exception_handler(request=request)
     if isinstance(exc, HelloWorldError):
         return render(request, 'error/404.html', {
             'error': exc,
             'status': 404,
         })
Esempio n. 3
0
def wrap_exception(request, exception):
  """Returns a HttpResponse with the exception in JSON form."""
  exc_info = sys.exc_info()

  LOGGER.error('%s: %s' % (exception.__class__.__name__, exception),
      exc_info=exc_info,
      extra={
        'status_code': 500,
        'request': request,
      }
  )

  # Don't wrap the exception during debugging.
  if settings.DEBUG and 'deb' in request.GET:
    return None

  if settings.HAVE_RAVEN:
    from raven.contrib.django.raven_compat.models import sentry_exception_handler
    sentry_exception_handler(request=request)

  result_data, http_code = util.to_json_error(exception, exc_info)
  result_data['meta'] = {
    'result': 'error'
  }
  return util.build_response(result_data, response_code=http_code)
Esempio n. 4
0
 def process_exception(self, request, exception):
     if isinstance(exception, BinkBaseException):
         return exception.get_message()
     else:
         #TODO: notify to sentry
         sentry_exception_handler(request=request)
         return ServerErrorException().get_message()
Esempio n. 5
0
 def process_exception(self, request, exception):
     """If an exception occurs, rollback the current transaction
     if it exists.
     """
     sentry_exception_handler(request=request)
     transaction_teardown_request(error=True)
     return None
Esempio n. 6
0
 def process_exception(self, request, exc):
     if isinstance(exc, HelloWorldError):
         sentry_exception_handler(request=request)
         ctx = {
             'error': exc,
             'status': 500,
         }
         return render(request, 'error.html', ctx, status=500)
def main():
    try:
        useless_articles = Article.calcualte_useless_articles()
        users = User.objects.only('id', 'seq_id')
        users = [default_key_user] + list(users)
        for u in users:
            u.remove_articles_from_candidateset(useless_articles)
    except:
        sentry_exception_handler()
Esempio n. 8
0
    def process_exception(self, request, exception):
        """
        app后台错误统一处理
        """

        self.exception = exception
        self.request = request

        # 用户自我感知的异常抛出
        if isinstance(exception, BlueException):
            logger.log(
                exception.LOG_LEVEL,
                (u"""捕获主动抛出异常, 具体异常堆栈->[%s] status_code->[%s] & """
                 u"""client_message->[%s] & args->[%s] """) % (
                    traceback.format_exc(),
                    exception.ERROR_CODE,
                    exception.message,
                    exception.args
                )
            )

            response = JsonResponse(exception.response_data())

            response.status_code = exception.STATUS_CODE
            return response

        # 用户未主动捕获的异常
        logger.error(
            (u"""捕获未处理异常,异常具体堆栈->[%s], 请求URL->[%s], """
             u"""请求方法->[%s] 请求参数->[%s]""") % (
                traceback.format_exc(),
                request.path,
                request.method,
                json.dumps(getattr(request, request.method, None))
            )
        )

        # 对于check开头函数进行遍历调用,如有满足条件的函数,则不屏蔽异常
        check_funtions = self.get_check_functions()
        for check_function in check_funtions:
            if check_function():
                return None

        response = JsonResponse({
            "result": False,
            'code': "50000",
            'message': u"系统异常,请联系管理员处理",
            'data': None
        })
        response.status_code = 500

        # notify sentry
        if sentry_exception_handler is not None:
            sentry_exception_handler(request=request)

        return response
Esempio n. 9
0
def log_exception(record, **kwargs):
    msg = json.dumps(record) if isinstance(record, dict) else record
    msg = '`'.join(map(str, record))
    with err_handler:
        exception(msg)

    try:
        sentry_exception_handler(extra={'msg': str(msg)}, **kwargs)
    except:
        pass
Esempio n. 10
0
def log_exception(record, **kwargs):
    msg = json.dumps(record) if isinstance(record, dict) else record
    msg = '`'.join(map(str, record))
    with err_handler:
        exception(msg)
        try:
            import traceback
            traceback.print_exc()
            sentry_exception_handler(extra={'msg': str(msg)}, **kwargs)
        except:
            pass
Esempio n. 11
0
def custom_exception_handler(exc, context):
    TESTING_MODE = os.path.basename(sys.argv[0]) in ('pytest', 'py.test')
    if not TESTING_MODE and context.get('request'):
        sentry_exception_handler(request=context["request"])
    response = default_django_rest_exception(exc, context)

    if response is None:
        return response
    error_data = get_error_data(response.status_code, response.data, exc)
    response.data = error_data
    return response
Esempio n. 12
0
    def process_exception(self, request, exception):
        """
        app后台错误统一处理
        """

        # 用户自我感知的异常抛出
        if isinstance(exception, BlueException):
            logger.warning(
                (u"""捕获主动抛出异常, 具体异常堆栈->[%s] status_code->[%s] & """
                 u"""client_message->[%s] & args->[%s] """) % (
                    traceback.format_exc(),
                    exception.error_code,
                    exception.message,
                    exception.args
                )
            )

            response = JsonResponse({
                'status_code': exception.error_code,
                'message': exception.message
            })

            response.status_code = exception.error_code // 100
            return response

        # 用户未主动捕获的异常
        logger.error(
            (u"""捕获未处理异常,异常具体堆栈->[%s], 请求URL->[%s], """
             u"""请求方法->[%s] 请求参数->[%s]""") % (
                traceback.format_exc(),
                request.path,
                request.method,
                json.dumps(getattr(request, request.method, None))
            )
        )

        # 判断是否在debug模式中,
        # 在这里判断是防止阻止了用户原本主动抛出的异常
        if settings.DEBUG:
            return None

        response = JsonResponse({
            'status_code': 50000,
            'message': u"系统异常,请联系管理员处理"
        })
        response.status_code = 500

        # notify sentry
        if sentry_exception_handler is not None:
            sentry_exception_handler(request=request)

        return response
Esempio n. 13
0
 def process_exception(self, request, exception):
     """If an exception occurs, rollback the current transaction
     if it exists.
     """
     sentry_exception_handler(request=request)
     try:
         commands.rollback()
     except OperationFailure as err:
         message = utils.get_error_message(err)
         if messages.NO_TRANSACTION_ERROR not in message:
             raise
     commands.disconnect()
     return None
Esempio n. 14
0
 def process_exception(self, request, exception):
     """If an exception occurs, rollback the current transaction
     if it exists.
     """
     sentry_exception_handler(request=request)
     try:
         commands.rollback()
     except OperationFailure as err:
         message = utils.get_error_message(err)
         if messages.NO_TRANSACTION_ERROR not in message:
             raise
     commands.disconnect()
     return None
def custom_exception_handler(exc, context):
    """
    DRF:
    http://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling
    Sentry/Raven:
    http://raven.readthedocs.org/en/latest/integrations/django.html#usage
    """
    response = exception_handler(exc, context)

    if not isinstance(exc, tuple(SILENT_DRF_EXCEPTIONS)):
        sentry_exception_handler(request=context['request']._request)

    logging.exception(exc.message, exc_info=exc)

    # throw the error in dev and testing
    if response or settings.ENVIRONMENT not in ['production', 'staging']:
        return response
    return Response({'error': exc.message}, status=500)
Esempio n. 16
0
    def process_exception(self, request, exception):
        """
        app后台错误统一处理
        """

        # 用户自我感知的异常抛出
        if isinstance(exception, BlueException):
            logger.log(exception.LOG_LEVEL,
                       (u"""捕获主动抛出异常, 具体异常堆栈->[%s] status_code->[%s] & """
                        u"""client_message->[%s] & args->[%s] """) %
                       (traceback.format_exc(), exception.ERROR_CODE,
                        exception.message, exception.args))

            response = JsonResponse(exception.response_data())

            response.status_code = exception.STATUS_CODE
            return response

        # 用户未主动捕获的异常
        logger.error((u"""捕获未处理异常,异常具体堆栈->[%s], 请求URL->[%s], """
                      u"""请求方法->[%s] 请求参数->[%s]""") %
                     (traceback.format_exc(), request.path, request.method,
                      json.dumps(getattr(request, request.method, None))))

        # 判断是否在debug模式中,
        # 在这里判断是防止阻止了用户原本主动抛出的异常
        if settings.DEBUG:
            return None

        response = JsonResponse({
            "result": False,
            'code': "50000",
            'message': u"系统异常,请联系管理员处理",
            'data': None
        })
        response.status_code = 500

        # notify sentry
        if sentry_exception_handler is not None:
            sentry_exception_handler(request=request)

        return response
Esempio n. 17
0
 def process_exception(self, request, exception):
     """If an exception occurs, clear the celery task queue so process_response has nothing."""
     sentry_exception_handler(request=request)
     celery_teardown_request(error=True)
     return None
Esempio n. 18
0
def log2sentry():
    try:
        sentry_exception_handler()
    except:
        pass
Esempio n. 19
0
    def process_exception(self, request, exception):
        sentry_exception_handler(request=request)

        if request.user.is_superuser:
            return technical_500_response(request, *sys.exc_info())
Esempio n. 20
0
 def process_exception(self, request, exception):
     """If an exception occurs, clear the celery task queue so process_response has nothing."""
     sentry_exception_handler(request=request)
     celery_teardown_request(error=True)
     return None
Esempio n. 21
0
def error404(request):
    from raven.contrib.django.raven_compat.models import sentry_exception_handler
    sentry_exception_handler(request=request)
    context = RequestContext(request)
    return render_to_response('errors/404.html', context_instance=context)
Esempio n. 22
0
 def process_exception(self, request, exception):
     sentry_exception_handler(request=request)
     api_globals.request = None
     return None
Esempio n. 23
0
 def process_exception(self, request, exception):
     # Make sure the exception signal is fired for Sentry
     sentry_exception_handler(request=request)
Esempio n. 24
0
 def process_exception(self, request, exception):
     sentry_exception_handler(request=request)
     api_globals.request = None
     return None
Esempio n. 25
0
 def process_exception(self, request, exception):
     request.META['REMOTE_ADDR'] = (request.META.get('HTTP_X_FORWARDED_FOR')
                                    or request.META['REMOTE_ADDR'])
     sentry_exception_handler(request=request)