检查 Azure 表存储中是否存在实体



我正在尝试通过分区键和行键从 Azure 表存储中检索实体。当我的表中实际上有一个带有这些键的实体时,这非常有用。

tableService.retrieveEntity(tableName, partition, row, (err, res, resp) => {
    ...    
}

但是,当找不到带有 for 键的实体时,我只是收到一个相当不清楚的错误,说"其中一个请求输入无效"......

未处理的拒绝存储错误:其中一个请求输入无效。

有没有办法检查特定分区键和行键是否存在实体?

我尝试了您的代码来检索不存在的实体,然后出现以下错误:

{ ...
  name: 'StorageError',
  message: 'The specified resource does not exist.nRequestId:c9f87517-0002-0028-5e32-660f88000000nTime:2017-01-04T02:30:10.0502844Z',
  code: 'ResourceNotFound',
  statusCode: 404,
  requestId: 'c9f87517-0002-0028-5e32-660f88000000' }

当我插入日期错误的实体时,代码如下所示:

var task = {
  PartitionKey: {'_': 'hometasks'},
  RowKey: {'_': '1'},
  description: {'_': 'take out the trash'},
  dueDate: {'_': 'somethingwronghere', '$': 'Edm.DateTime'}
};
tableSvc.insertEntity('mytable',task, function (error, result, response) {
  console.log(error);
});

然后我在下面收到与您相同的错误:

 { ...
  message: 'One of the request inputs is not valid.nRequestId:2e8e6c07-0002-003a-7135-663b94000000nTime:2017-01-04T02:49:02.8761981Z',
  code: 'InvalidInput',
  statusCode: 400,
  requestId: '2e8e6c07-0002-003a-7135-663b94000000' }

因此,请仔细检查您是否收到相应的错误消息。

最新更新