Azure-docs: CosmosClient throws on 404 Not Found

Created on 22 Aug 2019  Â·  3Comments  Â·  Source: MicrosoftDocs/azure-docs

The CosmosClient throws on 404 not found. The following needs to be converted to a try catch.

if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return null;
}


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author cosmos-dsvc cosmosdb-sqsubsvc doc-bug triaged

All 3 comments

@j82w Thank you for bringing this to our attention. We are evaluating this and will likely publish an update to the document per your suggestion. We greatly appreciate taking the time to point this out.

@SnehaGunda A recommendation is being made to tweak the code sample found in the following section: Perform CRUD operations on the data (link).

 public async Task<Item> GetItemAsync(string id)
   {
       ItemResponse<Item> response = await this._container.ReadItemAsync<Item>(id, new PartitionKey(id));
       if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
       {
           return null;
       }

Assigning to the content team for review, as there appears to be some conversation with regard to this.

@j82w Thanks for the suggestion, I submitted a fix to the code. The changes will be live on the doc on Monday.

We will close this issue if there aren't further questions.

please-close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ManuelMos picture ManuelMos  Â·  46Comments

danielstocker picture danielstocker  Â·  70Comments

DanijelMalik picture DanijelMalik  Â·  82Comments

xkobal picture xkobal  Â·  42Comments

m-andersen picture m-andersen  Â·  65Comments