#[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,
},
}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
Api
The server returned an error status with a well-formed TMF error body.
Problem
The response carries RFC 9457 problem details.
Fields
status: StatusCodeStatus 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: StatusCodeThe HTTP status code.
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: StatusCodeThe status the server answered with.
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.
Implementations§
Source§impl Error
impl Error
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
The HTTP status, when the failure came from a server response.
Sourcepub fn is_accepted(&self) -> bool
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),
}Sourcepub fn monitor(&self) -> Option<&str>
pub fn monitor(&self) -> Option<&str>
Where to poll for an asynchronous write, when the server named a place.
Sourcepub fn tmf_error(&self) -> Option<&TmfError>
pub fn tmf_error(&self) -> Option<&TmfError>
The parsed TMF error body, when the server supplied one.
Sourcepub fn problem(&self) -> Option<&ProblemDetails>
pub fn problem(&self) -> Option<&ProblemDetails>
The parsed RFC 9457 body, when supplied.
Sourcepub fn is_retryable(&self) -> bool
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.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Whether the failure was a 404.
Sourcepub fn is_precondition_failed(&self) -> bool
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 Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()