The SDK was designed with the following two scenarios.
This is for most users that want a simple interface that follows the normal Dot NET guidelines. Typed APIs is any method that returns the deserialized body, and can be identified as any method that does not return a ResponseMessage.
- Will throw the following exceptions types:
- CosmosException is used for all service related issues like 404 Not found
- ArgumentException
- OperationCancelledException
- CosmosException.ToString() includes the message, stack trace, and diagnostics. All of these properties are needed to troubleshoot issues
These APIs are designed for more advance scenario where perfomance is critical or it's being used in a middle tier service where a stream can just be passed through. Stream APIs return the content of the response as a stream, and can be identified as any method that returns a ResponseMessage.
- Returns a ResponseMessage instead of throwing a CosmosException for service related errors like a 404 Not Found. Throwing an exception causes unncessary overhead
- User still needs to handle the following exceptions.
- ArgumentException: This is thrown because it represent a bug in the user code, and should not be hit in production.
- OperationCancelledException: Not throwing an exception would violate the CancellationToken contract.
- ResponseMessage.IsSuccessStatusCode can be used to validate if the operation was successful
- ResponseMessage.EnsureSuccessStatusCode() will throw a CosmosException if the operation failed
- ResponseMessage.ErrorMessage contains the error message. It does not include the diagnostics.
- ResponseMessage.Diagnostics.ToString() contains information required to troubleshoot most issues.
To see a list of common error code and issues please see .NET SDK troubleshooting guide