feat: return LibError from Response::mime(&Self)
This commit is contained in:
parent
a6040176fb
commit
e92f0c62a2
2 changed files with 11 additions and 3 deletions
|
@ -3,6 +3,7 @@ pub enum LibError {
|
|||
InvalidUrlError(InvalidUrl),
|
||||
StatusOutOfRange(u8),
|
||||
MessageNotUtf8(std::string::FromUtf8Error),
|
||||
InvalidMime(mime::FromStrError),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for LibError {
|
||||
|
@ -40,6 +41,13 @@ impl From<std::string::FromUtf8Error> for LibError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<mime::FromStrError> for LibError {
|
||||
#[inline]
|
||||
fn from(err: mime::FromStrError) -> Self {
|
||||
Self::InvalidMime(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum InvalidUrl {
|
||||
ParseError(url::ParseError),
|
||||
SchemeNotGemini,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::status::Status;
|
||||
use crate::{status::Status, LibError};
|
||||
|
||||
type BodyStream = tokio_rustls::client::TlsStream<tokio::net::TcpStream>;
|
||||
|
||||
|
@ -25,8 +25,8 @@ impl Response {
|
|||
&self.message
|
||||
}
|
||||
|
||||
pub fn mime(self: &Self) -> Result<mime::Mime, mime::FromStrError> {
|
||||
self.message.parse()
|
||||
pub fn mime(self: &Self) -> Result<mime::Mime, LibError> {
|
||||
self.message.parse().map_err(|e| LibError::InvalidMime(e))
|
||||
}
|
||||
|
||||
pub fn body(self: &Self) -> &BodyStream {
|
||||
|
|
Loading…
Reference in a new issue