Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error { Api { status: StatusCode, error: Box<TmfError>, }, Problem { status: StatusCode, problem: Box<ProblemDetails>, }, Status { status: StatusCode, body: String, }, Accepted { status: StatusCode, monitor: Option<String>, }, Decode(Error), Encode(Error), Transport(TransportError), InvalidBaseUrl(String), NoEntityTag, CrossOrigin { url: String, base: String, }, }
Available on crate feature api only.
Expand description

Anything that can go wrong calling a TM Forum API.

Use Error::tmf_error for TMF630 fields and Error::problem for RFC 9457 problem details. Error::status returns the HTTP status.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Api

The server returned an error status with a well-formed TMF error body.

Fields

§status: StatusCode

The HTTP status code.

§error: Box<TmfError>

The parsed TMF630 error body.

§

Problem

The response carries RFC 9457 problem details.

Fields

§status: StatusCode

Status from the HTTP response.

§problem: Box<ProblemDetails>

Parsed problem details and extension members.

§

Status

The server returned an error status with an unrecognized or malformed error body.

Fields

§status: StatusCode

The HTTP status code.

§body: String

The raw response body, truncated for display.

§

Accepted

202 Accepted: the server took the request but has not completed it, so there is no resource to return yet.

Every v5 POST and PATCH declares this alongside its synchronous answer — a deployment may fulfil a write asynchronously. It is reported as an error because the call asked for a resource and did not get one, not because anything went wrong: match on it and poll.

Fields

§status: StatusCode

The status the server answered with.

§monitor: Option<String>

Where to poll, from Location or Content-Location, when the server named somewhere.

§

Decode(Error)

The response body could not be decoded into the expected type.

§

Encode(Error)

The request body could not be encoded.

§

Transport(TransportError)

The underlying HTTP stack failed.

§

InvalidBaseUrl(String)

The client was configured with an unusable base URL.

§

NoEntityTag

A conditional write was asked for against a resource the server issued no ETag for.

Tagged::update and Tagged::remove make a write conditional on the tag the read carried. When the server sent none there is nothing to make it conditional on, and sending the write anyway would be exactly the silent overwrite the precondition exists to prevent — so it is refused and said out loud instead.

Use the client’s plain update or delete method to write unconditionally.

§

CrossOrigin

A server-supplied URL pointed outside the API’s own origin, and was refused rather than followed.

Both the href of a …Ref and a Link: rel="next" header are written by the server, and the transport attaches this client’s credentials to whatever URL it is handed. Following one to another origin would hand a bearer token to whoever that origin belongs to, so the default is to refuse.

Deliberate federation across origins is still available, explicitly: TmfClient::get_cross_origin and ResolveRef::resolve_cross_origin.

Fields

§url: String

The URL that was refused.

§base: String

The client’s own base URL, whose origin it had to match.

Implementations§

Source§

impl Error

Source

pub fn status(&self) -> Option<StatusCode>

The HTTP status, when the failure came from a server response.

Source

pub fn is_accepted(&self) -> bool

Whether the server accepted the write but has not completed it.

match client.create_product_offering(&body).await {
    Ok(offering) => println!("created {:?}", offering.id),
    Err(error) if error.is_accepted() => {
        println!("queued; poll {:?}", error.monitor());
    }
    Err(error) => return Err(error),
}
Source

pub fn monitor(&self) -> Option<&str>

Where to poll for an asynchronous write, when the server named a place.

Source

pub fn tmf_error(&self) -> Option<&TmfError>

The parsed TMF error body, when the server supplied one.

Source

pub fn problem(&self) -> Option<&ProblemDetails>

The parsed RFC 9457 body, when supplied.

Source

pub fn is_retryable(&self) -> bool

Whether retrying the identical request could plausibly succeed.

True for 408, 429 and 5xx — except 501 Not Implemented, which is a statement about the endpoint rather than about this moment — and for transport failures. Whether the request may be re-sent is a separate question, and one RetryTransport answers by method.

Source

pub fn is_not_found(&self) -> bool

Whether the failure was a 404.

Source

pub fn is_precondition_failed(&self) -> bool

Whether a conditional write was refused because the resource had changed.

The outcome Tagged::update exists to produce: someone else edited the resource between the read and the write, so the write was refused rather than allowed to discard their change. Re-read and decide what to do — which is a decision only the caller can make, and the reason this is not retried automatically.

Uses the HTTP status for every error body format.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error

§

impl Move for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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