@@ -6,49 +6,32 @@ use base64::DecodeError;
66use http:: uri:: InvalidUri ;
77use serde_json:: error:: Error as JsonError ;
88
9- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
10- pub struct ErrorInfo {
11- pub code : u16 ,
12- pub errno : u16 ,
13- pub error : String ,
14- pub message : String ,
15- }
16-
17- impl fmt:: Display for ErrorInfo {
18- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
19- write ! (
20- f,
21- "code {}, errno {}: {} ({})" ,
22- self . code, self . errno, self . error, self . message
23- )
24- }
25- }
26-
27- #[ derive( Debug ) ]
9+ #[ derive( PartialEq , Debug , Clone , Ord , PartialOrd , Eq , Deserialize , Serialize , Hash ) ]
2810pub enum WebPushError {
29- /// An unknown error happened while encrypting or sending the message
11+ /// An unknown error happened encrypting the message,
3012 Unspecified ,
3113 /// Please provide valid credentials to send the notification
32- Unauthorized ( ErrorInfo ) ,
14+ Unauthorized ,
3315 /// Request was badly formed
34- BadRequest ( ErrorInfo ) ,
16+ BadRequest ( Option < String > ) ,
3517 /// Contains an optional `Duration`, until the user can retry the request
36- ServerError {
37- retry_after : Option < Duration > ,
38- info : ErrorInfo ,
39- } ,
18+ ServerError ( Option < Duration > ) ,
4019 /// The feature is not implemented yet
41- NotImplemented ( ErrorInfo ) ,
20+ NotImplemented ,
4221 /// The provided URI is invalid
4322 InvalidUri ,
4423 /// The URL specified is no longer valid and should no longer be used
45- EndpointNotValid ( ErrorInfo ) ,
24+ EndpointNotValid ,
4625 /// The URL specified is invalid and should not be used again
47- EndpointNotFound ( ErrorInfo ) ,
26+ EndpointNotFound ,
4827 /// Maximum allowed payload size is 3800 characters
4928 PayloadTooLarge ,
29+ /// Could not initialize a TLS connection
30+ TlsError ,
31+ /// Error in SSL signing
32+ SslError ,
5033 /// Error in reading a file
51- Io ( IoError ) ,
34+ IoError ,
5235 /// Make sure the message was addressed to a registration token whose
5336 /// package name matches the value passed in the request (Google).
5437 InvalidPackageName ,
@@ -64,9 +47,7 @@ pub enum WebPushError {
6447 InvalidResponse ,
6548 /// A claim had invalid data
6649 InvalidClaims ,
67- /// Response from push endpoint was too large
68- ResponseTooLarge ,
69- Other ( ErrorInfo ) ,
50+ Other ( String ) ,
7051}
7152
7253impl Error for WebPushError { }
@@ -104,8 +85,8 @@ impl From<isahc::Error> for WebPushError {
10485}
10586
10687impl From < IoError > for WebPushError {
107- fn from ( err : IoError ) -> WebPushError {
108- WebPushError :: Io ( err )
88+ fn from ( _ : IoError ) -> WebPushError {
89+ WebPushError :: IoError
10990 }
11091}
11192
@@ -119,53 +100,65 @@ impl WebPushError {
119100 pub fn short_description ( & self ) -> & ' static str {
120101 match * self {
121102 WebPushError :: Unspecified => "unspecified" ,
122- WebPushError :: Unauthorized ( _ ) => "unauthorized" ,
103+ WebPushError :: Unauthorized => "unauthorized" ,
123104 WebPushError :: BadRequest ( _) => "bad_request" ,
124- WebPushError :: ServerError { .. } => "server_error" ,
125- WebPushError :: NotImplemented ( _ ) => "not_implemented" ,
105+ WebPushError :: ServerError ( _ ) => "server_error" ,
106+ WebPushError :: NotImplemented => "not_implemented" ,
126107 WebPushError :: InvalidUri => "invalid_uri" ,
127- WebPushError :: EndpointNotValid ( _ ) => "endpoint_not_valid" ,
128- WebPushError :: EndpointNotFound ( _ ) => "endpoint_not_found" ,
108+ WebPushError :: EndpointNotValid => "endpoint_not_valid" ,
109+ WebPushError :: EndpointNotFound => "endpoint_not_found" ,
129110 WebPushError :: PayloadTooLarge => "payload_too_large" ,
111+ WebPushError :: TlsError => "tls_error" ,
130112 WebPushError :: InvalidPackageName => "invalid_package_name" ,
131113 WebPushError :: InvalidTtl => "invalid_ttl" ,
132114 WebPushError :: InvalidTopic => "invalid_topic" ,
133115 WebPushError :: InvalidResponse => "invalid_response" ,
134116 WebPushError :: MissingCryptoKeys => "missing_crypto_keys" ,
135117 WebPushError :: InvalidCryptoKeys => "invalid_crypto_keys" ,
136- WebPushError :: Io ( _) => "io_error" ,
118+ WebPushError :: SslError => "ssl_error" ,
119+ WebPushError :: IoError => "io_error" ,
137120 WebPushError :: Other ( _) => "other" ,
138121 WebPushError :: InvalidClaims => "invalidClaims" ,
139- WebPushError :: ResponseTooLarge => "response_too_large" ,
140122 }
141123 }
142124}
143125
144126impl fmt:: Display for WebPushError {
145127 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
146- match self {
147- WebPushError :: Unspecified => write ! ( f, "unspecified error" ) ,
148- WebPushError :: Unauthorized ( info) => write ! ( f, "unauthorized: {}" , info) ,
149- WebPushError :: BadRequest ( info) => write ! ( f, "bad request: {}" , info) ,
150- WebPushError :: ServerError { info, .. } => write ! ( f, "server error: {}" , info) ,
151- WebPushError :: PayloadTooLarge => write ! ( f, "maximum payload size of 3070 characters exceeded" ) ,
152- WebPushError :: InvalidUri => write ! ( f, "invalid uri provided" ) ,
153- WebPushError :: NotImplemented ( info) => write ! ( f, "not implemented: {}" , info) ,
154- WebPushError :: EndpointNotValid ( info) => write ! ( f, "endpoint not valid: {}" , info) ,
155- WebPushError :: EndpointNotFound ( info) => write ! ( f, "endpoint not found: {}" , info) ,
156- WebPushError :: Io ( err) => write ! ( f, "i/o error: {}" , err) ,
157- WebPushError :: InvalidPackageName => write ! (
158- f,
159- "package name of registration token does not match package name provided in the request"
160- ) ,
161- WebPushError :: InvalidTtl => write ! ( f, "invalid or missing ttl value" ) ,
162- WebPushError :: InvalidTopic => write ! ( f, "invalid topic value" ) ,
163- WebPushError :: InvalidResponse => write ! ( f, "could not parse response data" ) ,
164- WebPushError :: MissingCryptoKeys => write ! ( f, "request is missing cryptographic keys" ) ,
165- WebPushError :: InvalidCryptoKeys => write ! ( f, "request has invalid cryptographic keys" ) ,
166- WebPushError :: Other ( info) => write ! ( f, "other: {}" , info) ,
167- WebPushError :: InvalidClaims => write ! ( f, "at least one jwt claim was invalid" ) ,
168- WebPushError :: ResponseTooLarge => write ! ( f, "response from push endpoint was too large" ) ,
128+ match * self {
129+ WebPushError :: Unspecified =>
130+ write ! ( f, "An unknown error happened encrypting the message" ) ,
131+ WebPushError :: Unauthorized =>
132+ write ! ( f, "Please provide valid credentials to send the notification" ) ,
133+ WebPushError :: BadRequest ( _) =>
134+ write ! ( f, "Request was badly formed" ) ,
135+ WebPushError :: ServerError ( _) =>
136+ write ! ( f, "Server was unable to process the request, please try again later" ) ,
137+ WebPushError :: PayloadTooLarge =>
138+ write ! ( f, "Maximum allowed payload size is 3070 characters" ) ,
139+ WebPushError :: InvalidUri =>
140+ write ! ( f, "The provided URI is invalid" ) ,
141+ WebPushError :: NotImplemented =>
142+ write ! ( f, "The feature is not implemented yet" ) ,
143+ WebPushError :: EndpointNotValid =>
144+ write ! ( f, "The URL specified is no longer valid and should no longer be used" ) ,
145+ WebPushError :: EndpointNotFound =>
146+ write ! ( f, "The URL specified is invalid and should not be used again" ) ,
147+ WebPushError :: TlsError =>
148+ write ! ( f, "Could not initialize a TLS connection" ) ,
149+ WebPushError :: SslError =>
150+ write ! ( f, "Error signing with SSL" ) ,
151+ WebPushError :: IoError =>
152+ write ! ( f, "Error opening a file" ) ,
153+ WebPushError :: InvalidPackageName =>
154+ write ! ( f, "Make sure the message was addressed to a registration token whose package name matches the value passed in the request." ) ,
155+ WebPushError :: InvalidTtl => write ! ( f, "The TTL value provided was not valid or was not provided" ) ,
156+ WebPushError :: InvalidTopic => write ! ( f, "The Topic value provided was invalid" ) ,
157+ WebPushError :: InvalidResponse => write ! ( f, "The response data couldn't be parses" ) ,
158+ WebPushError :: MissingCryptoKeys => write ! ( f, "The request is missing cryptographic keys" ) ,
159+ WebPushError :: InvalidCryptoKeys => write ! ( f, "The request is having invalid cryptographic keys" ) ,
160+ WebPushError :: Other ( _) => write ! ( f, "An unknown error when connecting the notification service" ) ,
161+ WebPushError :: InvalidClaims => write ! ( f, "At least one JWT claim was invalid." )
169162 }
170163 }
171164}
0 commit comments