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;
}
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@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.