@@ -45,12 +45,12 @@ mod builds;
45
45
mod error;
46
46
mod sitemap;
47
47
48
- use std:: env;
48
+ use std:: { env, fmt } ;
49
49
use std:: error:: Error ;
50
50
use std:: time:: Duration ;
51
51
use std:: path:: PathBuf ;
52
52
use iron:: prelude:: * ;
53
- use iron:: { Handler , status} ;
53
+ use iron:: { self , Handler , status} ;
54
54
use iron:: headers:: { CacheControl , CacheDirective , ContentType } ;
55
55
use router:: { Router , NoRoute } ;
56
56
use staticfile:: Static ;
@@ -237,6 +237,34 @@ impl Handler for CratesfyiHandler {
237
237
} else {
238
238
panic ! ( "all cratesfyi errors should be of type Nope" ) ;
239
239
} ;
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
+
240
268
Self :: chain ( err) . handle ( req)
241
269
} )
242
270
}
0 commit comments