2016-06-09 58 views
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"); 

以上,clientAmazonDynamoDBClient類型的正確配置DB客戶端。

$error_type = $response->body->__type; 
$error_code = explode('#', $error_type)[1]; 
if($error_code == 'ResourceNotFoundException') 
{ 
    echo "Table ".$table_name." exists."; 
} 

回答

0

其實我結束了去一個完全不同的路線,因圍繞淨DescribeTable()功能規範 - 它拋出ResourceNotFoundException

如何做的相當的任何想法。

try 
{ 
    _client.DescribeTable(tableName); 
} 
catch (AmazonServiceException amazonServiceException) 
{ 
    if (amazonServiceException.GetType() != typeof(ResourceNotFoundException)) 
    { 
     throw; 
    } 

    return false; 
} 

return true;