コード例 #1
0
ファイル: app.py プロジェクト: Fiware/ops.Glancesync
def bad_request(error):
    """
    Default bad request error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    if isinstance(error.description, dict):
        message = error.description
    else:
        message = {
            "error": {
                "message": "Bad request",
                "code": httplib.BAD_REQUEST,
                "description": error.description
            }
        }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.BAD_REQUEST
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #2
0
def bad_request(error):
    """
    Default bad request error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    if isinstance(error.description, dict):
        message = error.description
    else:
        message = {
            "error": {
                "message": "Bad request",
                "code": httplib.BAD_REQUEST,
                "description": error.description
            }
        }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.BAD_REQUEST
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #3
0
ファイル: app.py プロジェクト: Fiware/ops.Glancesync
def unhandled_exception(exception):
    """
    When unhandled Exception.

    :param exception: The produced exception.
    :return: Response of the request with the error message.
    """
    message = {
        "error": {
            "message": "Unhandled exception",
            "code": httplib.INTERNAL_SERVER_ERROR
        }
    }
    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.INTERNAL_SERVER_ERROR
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #4
0
def unhandled_exception(exception):
    """
    When unhandled Exception.

    :param exception: The produced exception.
    :return: Response of the request with the error message.
    """
    message = {
        "error": {
            "message": "Unhandled exception",
            "code": httplib.INTERNAL_SERVER_ERROR
        }
    }
    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.INTERNAL_SERVER_ERROR
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #5
0
def run_in_thread(regionid, user):
    """
    Launch the synchronization in a new Thread
    :param regionid: region name to sync
    :param user: an instance of User
    """

    logger_api.info('Sync region {}, running in thread: {}'.format(regionid, threading.currentThread().getName()))
    try:
        glancesync = GlanceSync(options_dict=None)
        glancesync.sync_region(regionid, dry_run=False)

        row_changed = User.query.filter(User.task_id == user.task_id).one()
        row_changed.change_status(Task.SYNCED)
        db.session.commit()

    except Exception as e:
        logger_api.warn('Error in thread {}, with error: {}'.format(threading.currentThread().getName(), e.message))
        row_changed = User.query.filter(User.task_id == user.task_id).one()
        row_changed.change_status(Task.FAILED)
        db.session.commit()
コード例 #6
0
ファイル: app.py プロジェクト: Fiware/ops.Glancesync
def not_found(error):
    """
    Default not found error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        'error': {
            'message': 'Item not found: ',
            'description': error.description,
            'code': httplib.NOT_FOUND
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.NOT_FOUND
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #7
0
ファイル: app.py プロジェクト: Fiware/ops.Glancesync
def bad_method(error):
    """
    Default method not allowed error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        "error": {
            "message": "Bad method",
            "code": httplib.METHOD_NOT_ALLOWED,
            "description": error.description
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.METHOD_NOT_ALLOWED
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #8
0
def not_found(error):
    """
    Default not found error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        'error': {
            'message': 'Item not found: ',
            'description': error.description,
            'code': httplib.NOT_FOUND
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.NOT_FOUND
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #9
0
def bad_method(error):
    """
    Default method not allowed error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        "error": {
            "message": "Bad method",
            "code": httplib.METHOD_NOT_ALLOWED,
            "description": error.description
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.METHOD_NOT_ALLOWED
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #10
0
ファイル: app.py プロジェクト: Fiware/ops.Glancesync
def unauthorized(error):
    """
    Default unauthorized error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        'error': {
            'message': 'The request you have made requires authentication.',
            'description': error.description,
            "code": httplib.UNAUTHORIZED,
            'title': 'Unauthorized'
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.UNAUTHORIZED
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp
コード例 #11
0
def unauthorized(error):
    """
    Default unauthorized error message.

    :param error: The received error.
    :return: Response of the request with the error message.
    """
    message = {
        'error': {
            'message': 'The request you have made requires authentication.',
            'description': error.description,
            "code": httplib.UNAUTHORIZED,
            'title': 'Unauthorized'
        }
    }

    logger_api.warn(message)
    resp = jsonify(message)
    resp.status_code = httplib.UNAUTHORIZED
    resp.headers[SERVER_HEADER] = SERVER
    resp.headers[CONTENT_TYPE] = JSON_TYPE

    return resp