Skip to main content

CosmosStatus

Struct CosmosStatus 

Source
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-StatusHTTP 404HTTP 410
1002ReadSessionNotAvailablePartitionKeyRangeGone
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

Source

pub fn new(status_code: StatusCode) -> CosmosStatus

Creates a CosmosStatus with only an HTTP status code (no sub-status).

Source

pub fn with_sub_status(self, sub_status_code: u16) -> CosmosStatus

Sets the sub-status code on this CosmosStatus, returning the modified value.

Source

pub fn status_code(&self) -> StatusCode

Returns the HTTP status code.

Source

pub fn sub_status(&self) -> Option<SubStatusCode>

Returns the sub-status code, if present.

Source

pub fn is_success(&self) -> bool

Returns true if the HTTP status indicates success (2xx) or 304 Not Modified.

Source

pub fn is_throttled(&self) -> bool

Returns true if this is a throttling response (HTTP 429).

Source

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.

Source

pub fn is_gone(&self) -> bool

Returns true if this is an HTTP 410 Gone response.

Source

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.

Source

pub fn is_conflict(&self) -> bool

Returns true if this is an HTTP 409 Conflict response.

Source

pub fn is_precondition_failed(&self) -> bool

Returns true if this is an HTTP 412 Precondition Failed response.

Source

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).

Source

pub fn is_bad_request(&self) -> bool

Returns true if this is an HTTP 400 (bad request) response.

Source

pub fn is_unauthorized(&self) -> bool

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.

Source

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.

Source

pub fn is_service_unavailable(&self) -> bool

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.

Source

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.

Source

pub fn is_write_forbidden(&self) -> bool

Returns true if this is a write-forbidden error (HTTP 403, sub-status 3).

Source

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.

Source

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).

Source

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).

Source

pub fn is_transport_generated_503(&self) -> bool

Returns true if this indicates a transport-generated 503 (client-side).

Source

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-status

Trait Implementations§

Source§

impl Clone for CosmosStatus

Source§

fn clone(&self) -> CosmosStatus

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CosmosStatus

Source§

impl Debug for CosmosStatus

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for CosmosStatus

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for CosmosStatus

Source§

impl Hash for CosmosStatus

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CosmosStatus

Source§

fn eq(&self, other: &CosmosStatus) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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§

fn eq(&self, other: &StatusCode) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CosmosStatus

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CosmosStatus

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more