Example #1
0
        def wrapper(*args, **kw):
            for e in list(args) + kw.values():
                if isinstance(e, Exception):
                    exception = e
                    break
            else:
                raise IndicoError('Wrong usage of jsonify_error: No error found in params')

            tb = ''
            if logging_level != 'exception' and not isinstance(exception, no_tb_exceptions):
                tb = traceback.format_exc()
            getattr(Logger.get(logger_name), logging_level)(
                logger_message if logger_message else
                'Request {0} finished with {1}: {2}\n{3}'.format(
                    request, exception.__class__.__name__, exception, tb
                ).rstrip())

            # allow e.g. NoReportError to specify a status code without possibly
            # breaking old code that expects it with a 200 code.
            # new variable name since python2 doesn't have `nonlocal`...
            used_status = getattr(exception, 'http_status_code', status)
            if request.is_xhr or request.headers.get('Content-Type') == 'application/json':
                return create_json_error_answer(exception, status=used_status)
            else:
                args[0]._responseUtil.status = used_status
                return f(*args, **kw)
Example #2
0
        def wrapper(*args, **kw):
            for e in list(args) + kw.values():
                if isinstance(e, Exception):
                    exception = e
                    break
            else:
                raise IndicoError(
                    'Wrong usage of jsonify_error: No error found in params')

            tb = ''
            if logging_level != 'exception' and not isinstance(
                    exception, no_tb_exceptions):
                tb = traceback.format_exc()
            logger_fn = getattr(Logger.get(logger_name), logging_level)
            logger_fn(
                logger_message
                if logger_message else 'Request finished: {} ({})\n{}'.
                format(exception.__class__.__name__, exception, tb).rstrip())

            # allow e.g. NoReportError to specify a status code without possibly
            # breaking old code that expects it with a 200 code.
            # new variable name since python2 doesn't have `nonlocal`...
            used_status = getattr(exception, 'http_status_code', status)
            if request.is_xhr or request.headers.get(
                    'Content-Type') == 'application/json':
                if log_sentry:
                    sentry_log_exception()
                return create_json_error_answer(exception, status=used_status)
            else:
                args[0]._responseUtil.status = used_status
                return f(*args, **kw)
Example #3
0
File: base.py Project: Ictp/indico
 def decorator(*args, **keyargs):
     e = args[1]
     Logger.get('requestHandler').info('Request %s finished with %s: "%s"' % (request, e.__class__.__name__, e))
     if request.headers.get("Content-Type", "text/html").find("application/json") != -1:
         return create_json_error_answer(e)
     else:
         return func(*args, **keyargs)
Example #4
0
        def wrapper(*args, **kw):
            for e in list(args) + kw.values():
                if isinstance(e, Exception):
                    exception = e
                    break
            else:
                raise IndicoError('Wrong usage of jsonify_error: No error found in params')

            tb = traceback.format_exc() if logging_level != 'exception' else ''
            getattr(Logger.get(logger_name), logging_level)(
                logger_message if logger_message else
                'Request {0} finished with {1}: {2}\n{3}'.format(
                    request, exception.__class__.__name__, exception, tb
                ).rstrip())

            if request.is_xhr or request.headers.get('Content-Type') == 'application/json':
                return create_json_error_answer(exception)
            else:
                return f(*args, **kw)
Example #5
0
        def wrapper(*args, **kw):
            for e in list(args) + kw.values():
                if isinstance(e, Exception):
                    exception = e
                    break
            else:
                raise IndicoError('Wrong usage of jsonify_error: No error found in params')

            tb = traceback.format_exc() if logging_level != 'exception' else ''
            getattr(Logger.get(logger_name), logging_level)(
                logger_message if logger_message else
                'Request {0} finished with {1}: {2}\n{3}'.format(
                    request, exception.__class__.__name__, exception, tb
                ).rstrip())

            if request.is_xhr or request.headers.get('Content-Type') == 'application/json':
                return create_json_error_answer(exception)
            else:
                return f(*args, **kw)