@@ -45,12 +45,12 @@ mod builds;
4545mod error;
4646mod sitemap;
4747
48- use std:: env;
48+ use std:: { env, fmt } ;
4949use std:: error:: Error ;
5050use std:: time:: Duration ;
5151use std:: path:: PathBuf ;
5252use iron:: prelude:: * ;
53- use iron:: { Handler , status} ;
53+ use iron:: { self , Handler , status} ;
5454use iron:: headers:: { CacheControl , CacheDirective , ContentType } ;
5555use router:: { Router , NoRoute } ;
5656use staticfile:: Static ;
@@ -237,6 +237,34 @@ impl Handler for CratesfyiHandler {
237237 } else {
238238 panic ! ( "all cratesfyi errors should be of type Nope" ) ;
239239 } ;
240+
241+ match err {
242+ error:: Nope :: ResourceNotFound => {
243+ // print the path of the URL that triggered a 404 error
244+ struct DebugPath < ' a > ( & ' a iron:: Url ) ;
245+ impl < ' a > fmt:: Display for DebugPath < ' a > {
246+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
247+ for path_elem in self . 0 . path ( ) {
248+ write ! ( f, "/{}" , path_elem) ?;
249+ }
250+
251+ if let Some ( query) = self . 0 . query ( ) {
252+ write ! ( f, "?{}" , query) ?;
253+ }
254+
255+ if let Some ( hash) = self . 0 . fragment ( ) {
256+ write ! ( f, "#{}" , hash) ?;
257+ }
258+
259+ Ok ( ( ) )
260+ }
261+ }
262+
263+ debug ! ( "Path: {}" , DebugPath ( & req. url) ) ;
264+ }
265+ _ => { }
266+ }
267+
240268 Self :: chain ( err) . handle ( req)
241269 } )
242270 }
0 commit comments