Skip to content

Commit

Permalink
Merge pull request #50 from drogue-iot/propagate-error-kind
Browse files Browse the repository at this point in the history
Propagate the eio ErrorKind
  • Loading branch information
rmja authored Oct 24, 2023
2 parents 1890da8 + 3b0b27b commit 4731572
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit 4731572

Please sign in to comment.