Repository: seanmonstar/reqwest (language: rust)

Issue:
Have a way to know if there was a connection error
It's currently possible to know if the request failed because of a bad HTTP code (`is_status()`), something with the builder (`is_builder()`) and etc, but it's not possible to know if the request failed because of e.g. a DNS error, or a connection timeout, for example.

The reason is that the `Kind` enum is not exposed in the `Error` struct, and there are no functions to expose this information.


Discussion / hints:
Do you mean that an `is_request` method is missing? We could add that.

As for a connection error, that can be tricky. If you're trying to classify that in your app, you could check the `.source()` chain for specific error causes.
I'm sorry for my less than clear report. Yeah, I mean that `is_request` is missing (and a few others?).

As for the `.source()` chain, thanks for the tip, I wasn't aware of it. Though I think it's still better to use `is_request` as reqwest already does the classification itself. Would you like me to open a PR, or are you on it?

Thanks again.
Would you like to make a PR adding `is_request`? 
That's what I was asking, yeah, if you'd like me to do it, or if you're already on it. I guess I'll add all the missing types while at it too...

If you are going to do it, by all means, go ahead, was just suggesting to write the patch in case you're busy and it'd take a while until it gets in. :)
If you'd like, have at it!

Fix patch:
diff --git a/src/error.rs b/src/error.rs
index 5310631bc..b8e84b521 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<StatusCode> {
         match self.inner.kind {


Test patch: