@@ -3,9 +3,9 @@ use serde::Deserialize;
33use std:: error:: Error as StdError ;
44use std:: fmt;
55
6- /// A global error enum that encapsulates other more specific types of errors.
7- /// Some variants contain errors that in turn wrap errors from underlying libraries
8- /// like [`reqwest`]. These errors can be obtained from [`Error::source()`](StdError::source()) .
6+ /// A global error enum that contains all errors that are returned by this
7+ /// library. Some errors are wrappers for errors from underlying libraries.
8+ /// All errors (this enum as well as all contained structs) implement [`std::error::Error`] .
99#[ non_exhaustive]
1010#[ derive( Debug ) ]
1111pub enum Error {
@@ -138,6 +138,8 @@ impl fmt::Display for PrometheusErrorType {
138138 }
139139}
140140
141+ /// Is thrown when the [`Client`](crate::Client) or the underlying
142+ /// [`reqwest::Error`] fail to build or execute a request.
141143#[ derive( Debug ) ]
142144pub struct ClientError {
143145 pub ( crate ) message : & ' static str ,
@@ -156,6 +158,17 @@ impl StdError for ClientError {
156158 }
157159}
158160
161+ impl ClientError {
162+ /// Obtain the [`reqwest::Error`] that is the actual cause of this
163+ /// error or `None` if the error originated in [`Client`](crate::Client)
164+ /// itself.<br>
165+ pub fn inner ( & self ) -> Option < & reqwest:: Error > {
166+ self . source . as_ref ( )
167+ }
168+ }
169+
170+ /// Is thrown when the URL that is used to instantiate the [`Client`](crate::Client)
171+ /// is invalid.
159172#[ derive( Debug ) ]
160173pub struct ParseUrlError {
161174 pub ( crate ) message : & ' static str ,
@@ -173,3 +186,10 @@ impl StdError for ParseUrlError {
173186 Some ( & self . source )
174187 }
175188}
189+
190+ impl ParseUrlError {
191+ /// Obtain the [`url::ParseError`] that is the actual cause of this error.
192+ pub fn inner ( & self ) -> & url:: ParseError {
193+ & self . source
194+ }
195+ }
0 commit comments