Error

Enum Error 

Source
pub enum Error {
    Http {
        status: u16,
        message: String,
        body: Option<Bytes>,
    },
    Connection(String),
    Tls(String),
    Timeout,
    InvalidRequest(String),
    JsonSerialization(Error),
    JsonDeserialization {
        path: String,
        message: String,
    },
    FormSerialization(Error),
    QuerySerialization(Error),
    InvalidUrl(ParseError),
    TooManyRedirects {
        count: usize,
        max: usize,
    },
    InvalidRedirect(String),
}
Expand description

Main error type for pincer operations.

Variants§

§

Http

HTTP-level errors (non-2xx status codes).

Fields

§status: u16

HTTP status code.

§message: String

Error message.

§body: Option<Bytes>

Response body, if available.

§

Connection(String)

Network/connection errors.

§

Tls(String)

TLS/SSL errors.

§

Timeout

Request timeout.

§

InvalidRequest(String)

Invalid request configuration.

§

JsonSerialization(Error)

JSON serialization error.

§

JsonDeserialization

JSON deserialization error with path context.

Fields

§path: String

JSON path to the error (e.g., “user.address.city”).

§message: String

Error message.

§

FormSerialization(Error)

Form URL-encoded serialization error.

§

QuerySerialization(Error)

Query string serialization error.

§

InvalidUrl(ParseError)

URL parsing error.

§

TooManyRedirects

Too many redirects.

Fields

§count: usize

Number of redirects followed.

§max: usize

Maximum allowed redirects.

§

InvalidRedirect(String)

Invalid redirect response.

Implementations§

Source§

impl Error

Source

pub fn http(status: u16, message: impl Into<String>) -> Self

Create an HTTP error from status code and message.

Source

pub fn http_with_body( status: u16, message: impl Into<String>, body: Bytes, ) -> Self

Create an HTTP error with body.

Source

pub fn connection(message: impl Into<String>) -> Self

Create a connection error.

Source

pub fn tls(message: impl Into<String>) -> Self

Create a TLS error.

Source

pub fn invalid_request(message: impl Into<String>) -> Self

Create an invalid request error.

Source

pub fn json_deserialization( path: impl Into<String>, message: impl Into<String>, ) -> Self

Create a JSON deserialization error with path context.

Source

pub const fn is_timeout(&self) -> bool

Returns true if this is a timeout error.

Source

pub const fn is_connection(&self) -> bool

Returns true if this is a connection error.

Source

pub const fn status(&self) -> Option<u16>

Returns the HTTP status code if this is an HTTP error.

Source

pub fn is_client_error(&self) -> bool

Returns true if this is a client error (4xx).

Source

pub fn is_server_error(&self) -> bool

Returns true if this is a server error (5xx).

Source

pub fn is_not_found(&self) -> bool

Returns true if this is a 404 Not Found error.

Source

pub fn body(&self) -> Option<&Bytes>

Returns the response body if this is an HTTP error with a body.

Source

pub fn decode_body<T: DeserializeOwned>(&self) -> Option<Result<T>>

Try to decode the HTTP error body as JSON.

Returns Some(Ok(value)) if the error has a body and it deserializes successfully, Some(Err(error)) if the body exists but deserialization fails, or None if there is no body or this is not an HTTP error.

§Example
#[derive(Debug, Deserialize)]
struct ApiError {
    code: String,
    message: String,
}

match client.get_user(123).await {
    Ok(user) => println!("User: {:?}", user),
    Err(e) => {
        if let Some(Ok(api_error)) = e.decode_body::<ApiError>() {
            println!("API error: {} - {}", api_error.code, api_error.message);
        } else {
            println!("Error: {}", e);
        }
    }
}

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, __derive_more_f: &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
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
Source§

impl From<Error> for Error

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(value: ParseError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe 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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.