pub struct CosmosStatus { /* private fields */ }Expand description
Combined HTTP status code and optional Cosmos DB sub-status code.
This type keeps the HTTP status code and Cosmos sub-status code together, which is essential because the meaning of a sub-status code depends on the HTTP status code it’s paired with.
§Sub-Status Ambiguity
Some sub-status codes have different meanings depending on the HTTP status code:
| Sub-Status | HTTP 404 | HTTP 410 |
|---|---|---|
| 1002 | ReadSessionNotAvailable | PartitionKeyRangeGone |
| 1007 | — | CompletingSplitOrMerge (410), InsufficientBindablePartitions (503) |
| 1008 | — | CompletingPartitionMigration (410), DatabaseAccountNotFound (403) |
By pairing both codes, CosmosStatus can always resolve the correct name.
§Example
use azure_core::http::StatusCode;
use azure_data_cosmos_driver::models::CosmosStatus;
// Unambiguous status
let throttled = CosmosStatus::new(StatusCode::TooManyRequests).with_sub_status(3200);
assert_eq!(throttled.name(), Some("RUBudgetExceeded"));
assert!(throttled.is_throttled());
// Disambiguated by HTTP status code
let session_not_available = CosmosStatus::new(StatusCode::NotFound).with_sub_status(1002);
assert_eq!(session_not_available.name(), Some("ReadSessionNotAvailable"));
let pk_range_gone = CosmosStatus::new(StatusCode::Gone).with_sub_status(1002);
assert_eq!(pk_range_gone.name(), Some("PartitionKeyRangeGone"));Implementations§
Source§impl CosmosStatus
impl CosmosStatus
Sourcepub fn new(status_code: StatusCode) -> CosmosStatus
pub fn new(status_code: StatusCode) -> CosmosStatus
Creates a CosmosStatus with only an HTTP status code (no sub-status).
Sourcepub fn with_sub_status(self, sub_status_code: u16) -> CosmosStatus
pub fn with_sub_status(self, sub_status_code: u16) -> CosmosStatus
Sets the sub-status code on this CosmosStatus, returning the modified value.
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Returns the HTTP status code.
Sourcepub fn sub_status(&self) -> Option<SubStatusCode>
pub fn sub_status(&self) -> Option<SubStatusCode>
Returns the sub-status code, if present.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if the HTTP status indicates success (2xx) or 304 Not Modified.
Sourcepub fn is_throttled(&self) -> bool
pub fn is_throttled(&self) -> bool
Returns true if this is a throttling response (HTTP 429).
Sourcepub fn is_retry_with(&self) -> bool
pub fn is_retry_with(&self) -> bool
Returns true if this is an HTTP 449 RetryWith response.
449 RetryWith is returned by Cosmos backends for transient
concurrency conflicts (e.g. concurrent writes racing through the
store, RBAC info momentarily unavailable). The client is expected
to retry in the same region after a short delay. See
try_handle_retry_with in
driver::pipeline::retry_evaluation and the cross-SDK
RetryWithRetryPolicy for the policy.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Returns true if this is a “clean” HTTP 404 Not Found response — that
is, status code 404 with either no sub-status or sub-status 0
(UNKNOWN).
Non-zero sub-statuses on 404 carry meaningfully different semantics
(e.g. 1002 READ_SESSION_NOT_AVAILABLE is a transient session-
consistency signal, 1003 OWNER_RESOURCE_NOT_FOUND indicates the
parent database/container is missing, etc.) and would be misleading
to surface as a generic “not found”. Callers wanting to detect those
should match the corresponding CosmosStatus predicate or constant
explicitly.
Sourcepub fn is_conflict(&self) -> bool
pub fn is_conflict(&self) -> bool
Returns true if this is an HTTP 409 Conflict response.
Sourcepub fn is_precondition_failed(&self) -> bool
pub fn is_precondition_failed(&self) -> bool
Returns true if this is an HTTP 412 Precondition Failed response.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Returns true if this is an HTTP 408 (request timeout) response —
covers both a service-side timeout and a synthetic client-side
end-to-end timeout (408 / 20008).
Sourcepub fn is_bad_request(&self) -> bool
pub fn is_bad_request(&self) -> bool
Returns true if this is an HTTP 400 (bad request) response.
Returns true if this is an HTTP 401 (unauthorized) response —
covers both a service-side 401 and the SDK-synthesized
CLIENT_GENERATED_401 / AUTHENTICATION_TOKEN_ACQUISITION_FAILED.
Sourcepub fn is_forbidden(&self) -> bool
pub fn is_forbidden(&self) -> bool
Returns true if this is an HTTP 403 (forbidden) response. Use
is_write_forbidden for the specific
403 / 3 case that indicates the region is not the write region.
Returns true if this is an HTTP 503 (service unavailable) response
— covers both a service-side 503 and synthetic transport-generated
503s. Use is_transport_generated_503
to detect the synthetic case specifically.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Returns true if the error is generally considered transient and could
reasonably be retried by a higher layer.
The categorical retry-trigger set is 408 / 429 / 449 / 503, which
covers both real service responses (e.g. a service-side 503) and the
SDK’s synthetic transport-generated codes (TRANSPORT_GENERATED_503,
CLIENT_OPERATION_TIMEOUT on 408, etc.) since both share the same
HTTP status code by construction.
Sourcepub fn is_write_forbidden(&self) -> bool
pub fn is_write_forbidden(&self) -> bool
Returns true if this is a write-forbidden error (HTTP 403, sub-status 3).
Sourcepub fn is_database_account_not_found(&self) -> bool
pub fn is_database_account_not_found(&self) -> bool
Returns true for HTTP 403/sub-status 1008, where the region no longer owns the account.
Note: sub-status 1008 is overloaded on HTTP 410 for partition migration.
Sourcepub fn is_read_session_not_available(&self) -> bool
pub fn is_read_session_not_available(&self) -> bool
Returns true if this is a read-session-not-available error (HTTP 404, sub-status 1002).
Sourcepub fn is_partition_key_range_gone(&self) -> bool
pub fn is_partition_key_range_gone(&self) -> bool
Returns true if this is a partition-key-range-gone error (HTTP 410, sub-status 1002).
Sourcepub fn is_transport_generated_503(&self) -> bool
pub fn is_transport_generated_503(&self) -> bool
Returns true if this indicates a transport-generated 503 (client-side).
Sourcepub fn name(&self) -> Option<&'static str>
pub fn name(&self) -> Option<&'static str>
Returns the human-readable name of this status combination, if known.
Unlike the raw sub-status code, this method always resolves ambiguous codes correctly because it has the HTTP status code context.
Returns None for unknown sub-status codes or when no sub-status is present.
§Example
use azure_core::http::StatusCode;
use azure_data_cosmos_driver::models::CosmosStatus;
let status = CosmosStatus::new(StatusCode::NotFound).with_sub_status(1002);
assert_eq!(status.name(), Some("ReadSessionNotAvailable"));
let status = CosmosStatus::new(StatusCode::Gone).with_sub_status(1002);
assert_eq!(status.name(), Some("PartitionKeyRangeGone"));
let status = CosmosStatus::new(StatusCode::Ok);
assert_eq!(status.name(), None); // No sub-statusTrait Implementations§
Source§impl Clone for CosmosStatus
impl Clone for CosmosStatus
Source§fn clone(&self) -> CosmosStatus
fn clone(&self) -> CosmosStatus
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CosmosStatus
Source§impl Debug for CosmosStatus
impl Debug for CosmosStatus
Source§impl Display for CosmosStatus
impl Display for CosmosStatus
impl Eq for CosmosStatus
Source§impl Hash for CosmosStatus
impl Hash for CosmosStatus
Source§impl PartialEq for CosmosStatus
impl PartialEq for CosmosStatus
Source§impl PartialEq<StatusCode> for CosmosStatus
Allows ergonomic comparisons like assert_eq!(status, StatusCode::Ok).
impl PartialEq<StatusCode> for CosmosStatus
Allows ergonomic comparisons like assert_eq!(status, StatusCode::Ok).
Compares only the HTTP status code, ignoring sub-status. Use
CosmosStatus::sub_status explicitly when sub-status comparison is required.
Source§impl Serialize for CosmosStatus
impl Serialize for CosmosStatus
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for CosmosStatus
Auto Trait Implementations§
impl Freeze for CosmosStatus
impl RefUnwindSafe for CosmosStatus
impl Send for CosmosStatus
impl Sync for CosmosStatus
impl Unpin for CosmosStatus
impl UnsafeUnpin for CosmosStatus
impl UnwindSafe for CosmosStatus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.