CosmosClient with wrong key throws DocumentClientException instead of CosmosException
See original GitHub issueThis ticket relates with another one that was been previously closed (https://github.com/Azure/azure-cosmos-dotnet-v3/pull/785). I have basically implemented exactly what was described on that ticket. I am trying to create a cosmos client with a wrong key. I am able to get a DB and a container but as soon as I try to do a container action I get a DocumentClientException.
new CosmosClient(_appSettings.CosmosDbEndpoint, wrongKey,
new CosmosClientOptions()
{
ConnectionMode = ConnectionMode.Direct,
SerializerOptions = new CosmosSerializationOptions
{
PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
}
});
_database = client.GetDatabase(_databaseId);
_container = _database.GetContainer(_transactionsContainerId);
try
{
var response = await _container.CreateItemAsync(item);
response.Resource.ETag = response.ETag;
return response.Resource;
}
catch (CosmosException e)
{
...
}
catch (DocumentClientException e1)
{
...
}
catch (Exception e)
{
... The exception comes here as nothing seems to be able to catch a DocumentClientException
}
We are using Microsoft.Azure.Cosmos 3.13.0
One of my colleagues did some research and he found that the issue might be on this line of code. It might need to be inside the try catch: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs#L332
Some more details I have found. If we initialize the client with a valid key and then the key gets rotated, we get the CosmosException as expected with the following details:
Response status code does not indicate success: Unauthorized (401); Substatus: 0; ActivityId: XXX; Reason: (Message: {"Errors":["The MAC signature found in the HTTP request is not the same as the computed signature. Server used following string to sign - XXX...
However, as I mentioned above, the DocumentClientException is still thrown if the client is initialized already with an invalid key.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
@j82w This reproes on Write operations:
@NRam0s was right about the location for the fix, sharing PR in a min