CosmosException Class
- java.
lang. Object - java.
lang. Throwable - java.
lang. Exception - java.
lang. RuntimeException - com.
azure. core. exception. AzureException - com.
azure. cosmos. CosmosException
- com.
- com.
- java.
- java.
- java.
public class CosmosException
extends AzureException
This class defines a custom exception type for all operations on CosmosClient in the Azure Cosmos DB database service. Applications are expected to catch CosmosException and handle errors as appropriate when calling methods on CosmosClient.
Errors coming from the service during normal execution are converted to CosmosException before returning to the application with the following exception:
When a BE error is encountered during a QueryIterable iteration, an IllegalStateException is thrown instead of CosmosException.
When a transport level error happens that request is not able to reach the service, an IllegalStateException is thrown instead of CosmosException.
Constructor Summary
Method Summary
Modifier and Type | Method and Description |
---|---|
String |
getActivityId()
Gets the activity ID associated with the request. |
Cosmos |
getDiagnostics()
Gets the Cosmos Diagnostic Statistics associated with this exception. |
String | getMessage() |
double |
getRequestCharge()
Gets the request charge as request units (RU) consumed by the operation. |
Map<String,String> |
getResponseHeaders()
Gets the response headers as key-value pairs |
Duration |
getRetryAfterDuration()
Gets the recommended time duration after which the client can retry failed requests |
String |
getShortMessage()
Returns the error message without any diagnostics - using this method is only useful when also logging the getDiagnostics() separately. |
int |
getStatusCode()
Gets the http status code. |
int |
getSubStatusCode()
Gets the sub status code. |
String | toString() |
Methods inherited from java.lang.Object
Methods inherited from java.lang.Throwable
Constructor Details
CosmosException
protected CosmosException(int statusCode, CosmosError cosmosErrorResource, Map
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(int statusCode, Exception innerException)
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(int statusCode, String errorMessage)
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(int statusCode, String message, Map
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(String resourceAddress, int statusCode, CosmosError cosmosErrorResource, Map
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(String resourceAddress, int statusCode, CosmosError cosmosErrorResource, Map
Creates a new instance of the CosmosException class.
Parameters:
CosmosException
protected CosmosException(String message, Exception exception, Map
Creates a new instance of the CosmosException class.
Parameters:
Method Details
getActivityId
public String getActivityId()
Gets the activity ID associated with the request.
Returns:
getDiagnostics
public CosmosDiagnostics getDiagnostics()
Gets the Cosmos Diagnostic Statistics associated with this exception.
Returns:
getMessage
public String getMessage()
Overrides:
CosmosException.getMessage()getRequestCharge
public double getRequestCharge()
Gets the request charge as request units (RU) consumed by the operation.
For more information about the RU and factors that can impact the effective charges please visit Request Units in Azure Cosmos DB
Returns:
getResponseHeaders
public Map
Gets the response headers as key-value pairs
Returns:
getRetryAfterDuration
public Duration getRetryAfterDuration()
Gets the recommended time duration after which the client can retry failed requests
Returns:
getShortMessage
public String getShortMessage()
Returns the error message without any diagnostics - using this method is only useful when also logging the getDiagnostics() separately. Without diagnostics it will often be impossible to determine the root cause of an error.
Returns:
getStatusCode
public int getStatusCode()
Gets the http status code.
Returns:
getSubStatusCode
public int getSubStatusCode()
Gets the sub status code. The sub status code is exposed for informational purposes only - new sub status codes can be added anytime and applications should never take a dependency on certain sub status codes. For applications treating errors based on status code is sufficient.
Returns:
toString
public String toString()
Overrides:
CosmosException.toString()Applies to
Azure SDK for Java