0
我將這個answer引用到另一個非常類似的問題(唯一的區別是使用PHP)。描述表錯誤類型,亞馬遜DynamoDB
我已經看到一個例子,它從PHP中的AWS DynamoDB的DescribeTable
方法引發的異常中獲取詳細的錯誤信息(請參閱上面的鏈接答案);不過,我在C#中找到類似的信息時遇到了問題。
這是我迄今模仿:
var describeTableResponse = _client.DescribeTable(tableName);
var responseStatusCode = describeTableResponse.HttpStatusCode;
if (responseStatusCode == HttpStatusCode.OK)
{
return true;
}
else if(responseStatusCode == HttpStatusCode.BadRequest)
{
var error = // get detailed information; looking for ResourceNotFoundException
}
throw new AmazonDynamoDBException("Error performing the DescribeTable operation");
以上,client
是AmazonDynamoDBClient
類型的正確配置DB客戶端。
$error_type = $response->body->__type;
$error_code = explode('#', $error_type)[1];
if($error_code == 'ResourceNotFoundException')
{
echo "Table ".$table_name." exists.";
}