@@ -2,6 +2,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom};
22use std;
33use std:: fmt:: { self , Display } ;
44use std:: str:: FromStr ;
5+ use std:: error;
56use std:: thread:: sleep_ms;
67
78use mime:: { Mime , TopLevel , SubLevel , Attr , Value } ;
@@ -245,6 +246,49 @@ pub enum Error {
245246 Failure ( hyper:: client:: Response ) ,
246247}
247248
249+
250+ impl Display for Error {
251+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
252+ match * self {
253+ Error :: HttpError ( ref err) => err. fmt ( f) ,
254+ Error :: UploadSizeLimitExceeded ( ref resource_size, ref max_size) =>
255+ writeln ! ( f, "The media size {} exceeds the maximum allowed upload size of {}"
256+ , resource_size, max_size) ,
257+ Error :: MissingAPIKey => {
258+ writeln ! ( f, "The application's API key was not found in the configuration" ) . ok ( ) ;
259+ writeln ! ( f, "It is used as there are no Scopes defined for this method." )
260+ } ,
261+ Error :: MissingToken =>
262+ writeln ! ( f, "Didn't obtain authentication token from authenticator" ) ,
263+ Error :: Cancelled =>
264+ writeln ! ( f, "Operation cancelled by delegate" ) ,
265+ Error :: FieldClash ( field) =>
266+ writeln ! ( f, "The custom parameter '{}' is already provided natively by the CallBuilder." , field) ,
267+ Error :: JsonDecodeError ( ref err) => err. fmt ( f) ,
268+ Error :: Failure ( ref response) =>
269+ writeln ! ( f, "Http status indicates failure: {:?}" , response) ,
270+ }
271+ }
272+ }
273+
274+ impl error:: Error for Error {
275+ fn description ( & self ) -> & str {
276+ match * self {
277+ Error :: HttpError ( ref err) => err. description ( ) ,
278+ Error :: JsonDecodeError ( ref err) => err. description ( ) ,
279+ _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead"
280+ }
281+ }
282+
283+ fn cause ( & self ) -> Option < & error:: Error > {
284+ match * self {
285+ Error :: HttpError ( ref err) => err. cause ( ) ,
286+ Error :: JsonDecodeError ( ref err) => err. cause ( ) ,
287+ _ => None
288+ }
289+ }
290+ }
291+
248292/// A universal result type used as return for all calls.
249293pub type Result < T > = std:: result:: Result < T , Error > ;
250294
0 commit comments