@@ -28,10 +28,13 @@ impl fmt::Display for ErrorInfo {
2828 }
2929}
3030
31+ /// Web push failed.
3132#[ derive( Debug ) ]
33+ #[ non_exhaustive]
3234pub enum WebPushError {
33- /// An unknown error happened while encrypting or sending the message
34- Unspecified ,
35+ /// HTTP client error (network, DNS, TLS, protocol-level HTTP) while trying
36+ /// to send the notification.
37+ ClientError ( Box < dyn Error > ) ,
3538 /// Please provide valid credentials to send the notification
3639 Unauthorized ( ErrorInfo ) ,
3740 /// Request was badly formed
@@ -93,20 +96,6 @@ impl From<InvalidUri> for WebPushError {
9396 }
9497}
9598
96- #[ cfg( feature = "hyper-client" ) ]
97- impl From < hyper:: Error > for WebPushError {
98- fn from ( _: hyper:: Error ) -> Self {
99- Self :: Unspecified
100- }
101- }
102-
103- #[ cfg( feature = "isahc-client" ) ]
104- impl From < isahc:: Error > for WebPushError {
105- fn from ( _: isahc:: Error ) -> Self {
106- Self :: Unspecified
107- }
108- }
109-
11099impl From < IoError > for WebPushError {
111100 fn from ( err : IoError ) -> WebPushError {
112101 WebPushError :: Io ( err)
@@ -116,7 +105,7 @@ impl From<IoError> for WebPushError {
116105impl WebPushError {
117106 pub fn short_description ( & self ) -> & ' static str {
118107 match * self {
119- WebPushError :: Unspecified => "unspecified " ,
108+ WebPushError :: ClientError ( _ ) => "client_error " ,
120109 WebPushError :: Unauthorized ( _) => "unauthorized" ,
121110 WebPushError :: BadRequest ( _) => "bad_request" ,
122111 WebPushError :: ServerError { .. } => "server_error" ,
@@ -142,7 +131,7 @@ impl WebPushError {
142131impl fmt:: Display for WebPushError {
143132 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
144133 match self {
145- WebPushError :: Unspecified => write ! ( f, "unspecified error" ) ,
134+ WebPushError :: ClientError ( err ) => write ! ( f, "client error: {}" , err ) ,
146135 WebPushError :: Unauthorized ( info) => write ! ( f, "unauthorized: {}" , info) ,
147136 WebPushError :: BadRequest ( info) => write ! ( f, "bad request: {}" , info) ,
148137 WebPushError :: ServerError { info, .. } => write ! ( f, "server error: {}" , info) ,
@@ -168,21 +157,18 @@ impl fmt::Display for WebPushError {
168157 }
169158}
170159
171- pub struct RetryAfter ;
172- impl RetryAfter {
173- pub fn from_str ( header_value : & str ) -> Option < Duration > {
174- if let Ok ( seconds) = header_value. parse :: < u64 > ( ) {
175- Some ( Duration :: from_secs ( seconds) )
176- } else {
177- chrono:: DateTime :: parse_from_rfc2822 ( header_value)
178- . map ( |date_time| {
179- let systime: SystemTime = date_time. into ( ) ;
160+ pub fn parse_retry_after ( header_value : & str ) -> Option < Duration > {
161+ if let Ok ( seconds) = header_value. parse :: < u64 > ( ) {
162+ Some ( Duration :: from_secs ( seconds) )
163+ } else {
164+ chrono:: DateTime :: parse_from_rfc2822 ( header_value)
165+ . map ( |date_time| {
166+ let systime: SystemTime = date_time. into ( ) ;
180167
181- systime
182- . duration_since ( SystemTime :: now ( ) )
183- . unwrap_or_else ( |_| Duration :: new ( 0 , 0 ) )
184- } )
185- . ok ( )
186- }
168+ systime
169+ . duration_since ( SystemTime :: now ( ) )
170+ . unwrap_or_else ( |_| Duration :: new ( 0 , 0 ) )
171+ } )
172+ . ok ( )
187173 }
188174}
0 commit comments