feat: return LibError from Response::mime(&Self)

This commit is contained in:
DarkCat09 2024-08-01 10:29:34 +04:00
parent a6040176fb
commit e92f0c62a2
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
2 changed files with 11 additions and 3 deletions

View file

@ -3,6 +3,7 @@ pub enum LibError {
InvalidUrlError(InvalidUrl), InvalidUrlError(InvalidUrl),
StatusOutOfRange(u8), StatusOutOfRange(u8),
MessageNotUtf8(std::string::FromUtf8Error), MessageNotUtf8(std::string::FromUtf8Error),
InvalidMime(mime::FromStrError),
} }
impl From<std::io::Error> for LibError { 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 { pub enum InvalidUrl {
ParseError(url::ParseError), ParseError(url::ParseError),
SchemeNotGemini, SchemeNotGemini,

View file

@ -1,4 +1,4 @@
use crate::status::Status; use crate::{status::Status, LibError};
type BodyStream = tokio_rustls::client::TlsStream<tokio::net::TcpStream>; type BodyStream = tokio_rustls::client::TlsStream<tokio::net::TcpStream>;
@ -25,8 +25,8 @@ impl Response {
&self.message &self.message
} }
pub fn mime(self: &Self) -> Result<mime::Mime, mime::FromStrError> { pub fn mime(self: &Self) -> Result<mime::Mime, LibError> {
self.message.parse() self.message.parse().map_err(|e| LibError::InvalidMime(e))
} }
pub fn body(self: &Self) -> &BodyStream { pub fn body(self: &Self) -> &BodyStream {