File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ pub enum Nope {
1010 ResourceNotFound ,
1111 CrateNotFound ,
1212 NoResults ,
13+ InternalServerError ,
1314}
1415
1516impl fmt:: Display for Nope {
@@ -18,6 +19,7 @@ impl fmt::Display for Nope {
1819 Nope :: ResourceNotFound => "Requested resource not found" ,
1920 Nope :: CrateNotFound => "Requested crate not found" ,
2021 Nope :: NoResults => "Search yielded no results" ,
22+ Nope :: InternalServerError => "Internal server error" ,
2123 } )
2224 }
2325}
@@ -59,6 +61,13 @@ impl Handler for Nope {
5961 . to_resp ( "releases" )
6062 }
6163 }
64+ Nope :: InternalServerError => {
65+ // something went wrong, details should have been logged
66+ Page :: new ( "internal server error" . to_owned ( ) )
67+ . set_status ( status:: InternalServerError )
68+ . title ( "Internal server error" )
69+ . to_resp ( "error" )
70+ }
6271 }
6372 }
6473}
Original file line number Diff line number Diff line change @@ -159,10 +159,21 @@ impl Handler for CratesfyiHandler {
159159 . or_else ( |e| {
160160 let err = if let Some ( err) = e. error . downcast :: < error:: Nope > ( ) {
161161 * err
162- } else if e. error . downcast :: < NoRoute > ( ) . is_some ( ) {
162+ } else if e. error . downcast :: < NoRoute > ( ) . is_some ( )
163+ || e. response . status == Some ( status:: NotFound )
164+ {
163165 error:: Nope :: ResourceNotFound
166+ } else if e. response . status == Some ( status:: InternalServerError ) {
167+ log:: error!( "internal server error: {}" , e. error) ;
168+ error:: Nope :: InternalServerError
164169 } else {
165- panic ! ( "all cratesfyi errors should be of type Nope" ) ;
170+ log:: error!(
171+ "No error page for status {:?}; {}" ,
172+ e. response. status,
173+ e. error
174+ ) ;
175+ // TODO: add in support for other errors that are actually used
176+ error:: Nope :: InternalServerError
166177 } ;
167178
168179 if let error:: Nope :: ResourceNotFound = err {
@@ -186,7 +197,7 @@ impl Handler for CratesfyiHandler {
186197 }
187198 }
188199
189- debug ! ( "Path not found: {}" , DebugPath ( & req. url) ) ;
200+ debug ! ( "Path not found: {}; {} " , DebugPath ( & req. url) , e . error ) ;
190201 }
191202
192203 Self :: chain ( self . pool . clone ( ) , err) . handle ( req)
You can’t perform that action at this time.
0 commit comments