@@ -282,33 +282,31 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
282
282
rendering_time. step ( "match version" ) ;
283
283
284
284
// Check the database for releases with the requested version while doing the following:
285
+ // * If no matching releases are found, return a 404 with the underlying error
286
+ // Then:
285
287
// * If both the name and the version are an exact match, return the version of the crate.
286
288
// * If there is an exact match, but the requested crate name was corrected (dashes vs. underscores), redirect to the corrected name.
287
289
// * If there is a semver (but not exact) match, redirect to the exact version.
288
- // * Otherwise, return a 404.
289
- let version = match match_version ( & mut conn , & name , url_version ) {
290
- Ok ( match_vers ) => {
291
- match match_vers . version {
292
- MatchSemver :: Exact ( ( version, _) ) => {
293
- // Redirect when the requested crate name isn't correct
294
- if let Some ( name) = match_vers . corrected_name {
295
- return redirect ( & name, & version, & req_path) ;
296
- }
290
+ let release_found = match_version ( & mut conn , & name , url_version )
291
+ . map_err ( |err| IronError :: new ( err , status :: NotFound ) ) ? ;
292
+
293
+ let version = match release_found . version {
294
+ MatchSemver :: Exact ( ( version, _) ) => {
295
+ // Redirect when the requested crate name isn't correct
296
+ if let Some ( name) = release_found . corrected_name {
297
+ return redirect ( & name, & version, & req_path) ;
298
+ }
297
299
298
- version
299
- }
300
+ version
301
+ }
300
302
301
- // Redirect when the requested version isn't correct
302
- MatchSemver :: Semver ( ( v, _) ) => {
303
- // to prevent cloudfront caching the wrong artifacts on URLs with loose semver
304
- // versions, redirect the browser to the returned version instead of loading it
305
- // immediately
306
- return redirect ( & name, & v, & req_path) ;
307
- }
308
- }
303
+ // Redirect when the requested version isn't correct
304
+ MatchSemver :: Semver ( ( v, _) ) => {
305
+ // to prevent cloudfront caching the wrong artifacts on URLs with loose semver
306
+ // versions, redirect the browser to the returned version instead of loading it
307
+ // immediately
308
+ return redirect ( & name, & v, & req_path) ;
309
309
}
310
- // Return a 404, as a crate by that name and version requirement doesn't exist
311
- Err ( err) => return Err ( IronError :: new ( err, status:: NotFound ) ) ,
312
310
} ;
313
311
314
312
rendering_time. step ( "crate details" ) ;
@@ -563,6 +561,12 @@ pub fn badge_handler(req: &mut Request) -> IronResult<Response> {
563
561
return Ok ( super :: redirect ( iron_url) ) ;
564
562
}
565
563
564
+ Err ( Nope :: VersionNotFound ) => BadgeOptions {
565
+ subject : "docs" . to_owned ( ) ,
566
+ status : "version not found" . to_owned ( ) ,
567
+ color : "#e05d44" . to_owned ( ) ,
568
+ } ,
569
+
566
570
Err ( _) => BadgeOptions {
567
571
subject : "docs" . to_owned ( ) ,
568
572
status : "no builds" . to_owned ( ) ,
0 commit comments