Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate the eio ErrorKind #50

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ pub enum Error {
AlreadySent,
/// An invalid number of bytes were written to request body
IncorrectBodyWritten,
/// The underlying connection was closed
ConnectionClosed,
/// The underlying connection was closed while being used
ConnectionAborted,
}

impl embedded_io::Error for Error {
fn kind(&self) -> embedded_io::ErrorKind {
embedded_io::ErrorKind::Other
match self {
Error::Network(kind) => *kind,
Error::ConnectionAborted => embedded_io::ErrorKind::ConnectionAborted,
_ => embedded_io::ErrorKind::Other,
}
}
}

Expand All @@ -56,7 +60,7 @@ impl From<embedded_io::ErrorKind> for Error {
impl<E: embedded_io::Error> From<ReadExactError<E>> for Error {
fn from(value: ReadExactError<E>) -> Self {
match value {
ReadExactError::UnexpectedEof => Error::ConnectionClosed,
ReadExactError::UnexpectedEof => Error::ConnectionAborted,
ReadExactError::Other(e) => Error::Network(e.kind()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
})?;

if n == 0 {
return Err(Error::ConnectionClosed);
return Err(Error::ConnectionAborted);
}

pos += n;
Expand Down Expand Up @@ -413,7 +413,7 @@ where
.map(|data| &data[..data.len().min(self.remaining)])?;

if loaded.is_empty() {
return Err(Error::ConnectionClosed);
return Err(Error::ConnectionAborted);
}

Ok(loaded)
Expand Down