Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS DynamoDB DocumentClient未引发预期错误_Amazon Web Services_Amazon Dynamodb - Fatal编程技术网

Amazon web services AWS DynamoDB DocumentClient未引发预期错误

Amazon web services AWS DynamoDB DocumentClient未引发预期错误,amazon-web-services,amazon-dynamodb,Amazon Web Services,Amazon Dynamodb,我正在使用DynamoDB存储数据,并尝试使用JavaScript读取项目。我有一个函数可以从指定的表中读取项,但我想检测表中何时不存在项: function getChapterLocations() { var table = bibleSelect.value.replace(/\s/g, ''); var chapter = bookSelect.value + " " + chapterSelect.value; var params = { T

我正在使用DynamoDB存储数据,并尝试使用JavaScript读取项目。我有一个函数可以从指定的表中读取项,但我想检测表中何时不存在项:

function getChapterLocations() {
    var table = bibleSelect.value.replace(/\s/g, '');
    var chapter = bookSelect.value + " " + chapterSelect.value;
    var params = {
        TableName: table,
        Key:{
            "chapter": chapter
        }
    };
    var docClient = new AWS.DynamoDB.DocumentClient();
    docClient.get(params, function(err, data) {
        if (err) {
            currentLocations = {};
        } else {
            currentLocations = data.Item.locations;
        }
        getText();
    });
}
问题是,即使表中不存在项,
err
始终为
null
。当一个项目不存在时,我得到的只是一个错误,在控制台中看起来像这样:

呼叫侦听器 发射发射事件


我只想忽略这个错误,但当一个项不存在时,它会阻止调用
getText()

如果找不到temp,为什么会收到错误。数据将是空的。GetItem操作返回具有给定主键的项的一组属性。如果没有匹配项,GetItem不会返回任何数据,响应中也不会有item元素。好的,谢谢,所以我真正的问题是当我试图从data.Item中访问位置时,没有Item。我通过检查data.Item是否为null而不是检查err是否为null.yes来修复它。您还应该检查错误是否为真,并处理错误,以便程序不会崩溃