refactor: clean up errors; docs: add doc-comments to error.rs
This commit is contained in:
parent
03420c8e8d
commit
9de12169a6
2 changed files with 20 additions and 12 deletions
|
@ -99,7 +99,7 @@ impl Client {
|
||||||
/// Check the inner error if you need to determine what exactly happened
|
/// Check the inner error if you need to determine what exactly happened
|
||||||
/// - [`LibError::StatusOutOfRange`] means that a server returned an incorrect status code
|
/// - [`LibError::StatusOutOfRange`] means that a server returned an incorrect status code
|
||||||
/// (less than 10 or greater than 69).
|
/// (less than 10 or greater than 69).
|
||||||
/// - [`LibError::MessageNotUtf8`] is returned when metadata (the text after the status code)
|
/// - [`LibError::DataNotUtf8`] is returned when metadata (the text after a status code)
|
||||||
/// is not in UTF-8 and cannot be converted to string without errors.
|
/// is not in UTF-8 and cannot be converted to string without errors.
|
||||||
pub async fn request_with_host(
|
pub async fn request_with_host(
|
||||||
&self,
|
&self,
|
||||||
|
|
30
src/error.rs
30
src/error.rs
|
@ -1,10 +1,19 @@
|
||||||
|
//! Library error structures and enums
|
||||||
|
|
||||||
|
/// Main error structure, also a wrapper for everything else
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LibError {
|
pub enum LibError {
|
||||||
|
/// General I/O error
|
||||||
|
// TODO: separate somehow
|
||||||
IoError(std::io::Error),
|
IoError(std::io::Error),
|
||||||
|
/// URL parse or check error
|
||||||
InvalidUrlError(InvalidUrl),
|
InvalidUrlError(InvalidUrl),
|
||||||
|
/// Response status code is out of [10; 69] range
|
||||||
StatusOutOfRange(u8),
|
StatusOutOfRange(u8),
|
||||||
MessageNotUtf8(std::string::FromUtf8Error),
|
/// Response metadata or content cannot be parsed
|
||||||
BodyNotUtf8(std::str::Utf8Error),
|
/// as a UTF-8 string without errors
|
||||||
|
DataNotUtf8(std::string::FromUtf8Error),
|
||||||
|
/// Provided string is not a valid MIME type
|
||||||
InvalidMime(mime::FromStrError),
|
InvalidMime(mime::FromStrError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,14 +48,7 @@ impl LibError {
|
||||||
impl From<std::string::FromUtf8Error> for LibError {
|
impl From<std::string::FromUtf8Error> for LibError {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(err: std::string::FromUtf8Error) -> Self {
|
fn from(err: std::string::FromUtf8Error) -> Self {
|
||||||
Self::MessageNotUtf8(err)
|
Self::DataNotUtf8(err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<std::str::Utf8Error> for LibError {
|
|
||||||
#[inline]
|
|
||||||
fn from(err: std::str::Utf8Error) -> Self {
|
|
||||||
Self::BodyNotUtf8(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +59,17 @@ impl From<mime::FromStrError> for LibError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// URL parse or check error
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InvalidUrl {
|
pub enum InvalidUrl {
|
||||||
|
/// Provided string cannot be parsed as a valid URL with [`url::Url`]
|
||||||
ParseError(url::ParseError),
|
ParseError(url::ParseError),
|
||||||
|
/// URL scheme is not `gemini://`
|
||||||
SchemeNotGemini,
|
SchemeNotGemini,
|
||||||
|
/// URL contains userinfo -- `user:pswd@` --
|
||||||
|
/// which is forbidden by Gemini spec
|
||||||
UserinfoPresent,
|
UserinfoPresent,
|
||||||
NoHostFound,
|
/// Could not extract host from the URL or convert host and port into
|
||||||
|
/// [`std::net::SocketAddr`] or [`crate::certs::ServerName`]
|
||||||
ConvertError,
|
ConvertError,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue