Skip to content

Commit

Permalink
fix: user created Error would not return provided Reason
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Sep 30, 2021
1 parent 44cb57c commit fc73fc9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,9 @@ impl Error {
/// action taken by the peer (i.e. a protocol error).
pub fn reason(&self) -> Option<Reason> {
match self.kind {
Kind::Reset(_, reason, _) | Kind::GoAway(_, reason, _) => Some(reason),
Kind::Reset(_, reason, _) | Kind::GoAway(_, reason, _) | Kind::Reason(reason) => {
Some(reason)
}
_ => None,
}
}
@@ -167,3 +169,15 @@ impl fmt::Display for Error {
}

impl error::Error for Error {}

#[cfg(test)]
mod tests {
use super::Error;
use crate::Reason;

#[test]
fn error_from_reason() {
let err = Error::from(Reason::HTTP_1_1_REQUIRED);
assert_eq!(err.reason(), Some(Reason::HTTP_1_1_REQUIRED));
}
}

0 comments on commit fc73fc9

Please sign in to comment.