From 2e28f553ba2455b20437186930299df5e4e4b587 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Sat, 21 Oct 2017 13:00:35 -0700 Subject: [PATCH] Expose h2::Error::reason (#166) --- src/error.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/error.rs b/src/error.rs index f9dac4b..d84f7af 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,6 +29,19 @@ enum Kind { // ===== impl Error ===== +impl Error { + /// If the error was caused by the remote peer, the error reason. + /// + /// This is either an error received by the peer or caused by an invalid + /// action taken by the peer (i.e. a protocol error). + pub fn reason(&self) -> Option { + match self.kind { + Kind::Proto(reason) => Some(reason), + _ => None, + } + } +} + impl From for Error { fn from(src: proto::Error) -> Error { use proto::Error::*;