示例#1
0
文件: http.py 项目: ES-DOC/esdoc-api
def _log(handler, msg, is_error=False):
    """Logs an error response.

    """
    msg = "[{}]: --> {}".format(id(handler), msg)
    if is_error:
        logger.log_web_error(msg)
    else:
        logger.log_web(msg)
示例#2
0
文件: http.py 项目: ES-DOC/esdoc-api
def process_request(handler, tasks, error_tasks=None):
    """Invokes a set of HTTP request processing tasks.

    :param tornado.web.RequestHandler handler: Request processing handler.
    :param list tasks: Collection of processing tasks.
    :param list error_tasks: Collection of error processing tasks.

    """
    # Log request.
    msg = "[{0}]: executing --> {1}"
    msg = msg.format(id(handler), handler)
    logger.log_web(msg)

    # Extend tasksets.
    tasks = _get_tasks(
        [http_validator.validate_request],
        tasks,
        [_log_success, _write_success]
        )
    error_tasks = _get_tasks(
        [],
        error_tasks or [],
        [log_error, write_error]
        )

    # Invoke tasksets:
    # ... normal processing;
    for task in tasks:
        try:
            _invoke(handler, task)
        except Exception as err:
            # ... error processing;
            try:
                for task in error_tasks:
                    _invoke(handler, task, err)
            # ... error processing exceptions are suppressed
            except:
                pass
            break