diff --git a/src/lib.rs b/src/lib.rs index 2a13cce..0923b60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, + } } } @@ -56,7 +60,7 @@ impl From for Error { impl From> for Error { fn from(value: ReadExactError) -> Self { match value { - ReadExactError::UnexpectedEof => Error::ConnectionClosed, + ReadExactError::UnexpectedEof => Error::ConnectionAborted, ReadExactError::Other(e) => Error::Network(e.kind()), } } diff --git a/src/response.rs b/src/response.rs index 3132865..7986cdb 100644 --- a/src/response.rs +++ b/src/response.rs @@ -51,7 +51,7 @@ where })?; if n == 0 { - return Err(Error::ConnectionClosed); + return Err(Error::ConnectionAborted); } pos += n; @@ -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)