49 lines
1.6 KiB
Rust
49 lines
1.6 KiB
Rust
//
|
|
use derive_more::derive::From;
|
|
|
|
/// The Errors that may occur within [kxio::net][crate::net].
|
|
#[derive(Debug, From, derive_more::Display)]
|
|
pub enum Error {
|
|
/// The Errors that may occur when processing a `Request`.
|
|
///
|
|
/// Note: Errors may include the full URL used to make the `Request`. If the URL
|
|
/// contains sensitive information (e.g. an API key as a query parameter), be
|
|
/// sure to remove it ([`without_url`](reqwest::Error::without_url))
|
|
Reqwest(reqwest::Error),
|
|
|
|
/// The Errors that may occur when processing a `Request`.
|
|
///
|
|
/// The cause has been converted to a String.
|
|
Request(String),
|
|
|
|
Url(url::ParseError),
|
|
|
|
/// There was network request that doesn't match any that were expected
|
|
#[display("Unexpected request: {0}", 0.to_string())]
|
|
UnexpectedMockRequest(reqwest::Request),
|
|
|
|
/// There was an error accessing the list of expected requests.
|
|
RwLockLocked,
|
|
|
|
/// There was an error making a network request.
|
|
Http(http::Error),
|
|
|
|
/// Attempted to extract a [MockNet][super::MockNet] from a [Net][super::Net] that does not contain one.
|
|
NetIsNotAMock,
|
|
}
|
|
impl std::error::Error for Error {}
|
|
impl Clone for Error {
|
|
fn clone(&self) -> Self {
|
|
match self {
|
|
Self::Reqwest(req) => Self::Request(req.to_string()),
|
|
err => err.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Represents a success or a failure within [kxio::net][crate::net].
|
|
///
|
|
/// Any failure is related to `std::io`, a Path Traversal
|
|
/// (i.e. trying to escape the base of the `FileSystem`),
|
|
/// or attempting to use a file as a directory or /vise versa/.
|
|
pub type Result<T> = core::result::Result<T, Error>;
|