Separate timeout and connection dropped errors out (#30457)
This commit is contained in:
parent
39da72161f
commit
471e02d48f
25 changed files with 313 additions and 115 deletions
|
@ -1025,6 +1025,29 @@ pub fn get_system_shell() -> String {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConnectionResult<O> {
|
||||
Timeout,
|
||||
ConnectionReset,
|
||||
Result(anyhow::Result<O>),
|
||||
}
|
||||
|
||||
impl<O> ConnectionResult<O> {
|
||||
pub fn into_response(self) -> anyhow::Result<O> {
|
||||
match self {
|
||||
ConnectionResult::Timeout => anyhow::bail!("Request timed out"),
|
||||
ConnectionResult::ConnectionReset => anyhow::bail!("Server reset the connection"),
|
||||
ConnectionResult::Result(r) => r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<O> From<anyhow::Result<O>> for ConnectionResult<O> {
|
||||
fn from(result: anyhow::Result<O>) -> Self {
|
||||
ConnectionResult::Result(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue