Skip to content

Commit fc73fc9

Browse files
committed
fix: user created Error would not return provided Reason
1 parent 44cb57c commit fc73fc9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/error.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ impl Error {
5050
/// action taken by the peer (i.e. a protocol error).
5151
pub fn reason(&self) -> Option<Reason> {
5252
match self.kind {
53-
Kind::Reset(_, reason, _) | Kind::GoAway(_, reason, _) => Some(reason),
53+
Kind::Reset(_, reason, _) | Kind::GoAway(_, reason, _) | Kind::Reason(reason) => {
54+
Some(reason)
55+
}
5456
_ => None,
5557
}
5658
}
@@ -167,3 +169,15 @@ impl fmt::Display for Error {
167169
}
168170

169171
impl error::Error for Error {}
172+
173+
#[cfg(test)]
174+
mod tests {
175+
use super::Error;
176+
use crate::Reason;
177+
178+
#[test]
179+
fn error_from_reason() {
180+
let err = Error::from(Reason::HTTP_1_1_REQUIRED);
181+
assert_eq!(err.reason(), Some(Reason::HTTP_1_1_REQUIRED));
182+
}
183+
}

0 commit comments

Comments
 (0)