From 668e89b78ae1e7a0e88fb7f99649b7c907d2f0da Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 13 Jun 2020 17:52:02 +0300 Subject: [PATCH] Error: add functions to check more error types. (#945) There are functions to check if the error is from an array of different reasons, but there were no functions to check if the failure was due to the rest of the possible error reasons. This commit adds though. Fixes #942 --- src/error.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/error.rs b/src/error.rs index 5310631..b8e84b5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -94,6 +94,30 @@ impl Error { false } + /// Returns true if the error is related to the request + pub fn is_request(&self) -> bool { + match self.inner.kind { + Kind::Request => true, + _ => false, + } + } + + /// Returns true if the error is related to the request or response body + pub fn is_body(&self) -> bool { + match self.inner.kind { + Kind::Body => true, + _ => false, + } + } + + /// Returns true if the error is related to decoding the response's body + pub fn is_decode(&self) -> bool { + match self.inner.kind { + Kind::Decode => true, + _ => false, + } + } + /// Returns the status code, if the error was generated from a response. pub fn status(&self) -> Option { match self.inner.kind {