diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index cd0189a10..c62f64f9d 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -830,6 +830,7 @@ pub(crate) async fn json_download_handler( Path(params): Path, mut conn: DbConnection, Extension(config): Extension>, + Extension(storage): Extension>, ) -> AxumResult { let matched_release = match_version(&mut conn, ¶ms.name, ¶ms.version) .await? @@ -875,6 +876,10 @@ pub(crate) async fn json_download_handler( format_version, ); + if !storage.exists(&storage_path).await? { + return Err(AxumNope::ResourceNotFound); + } + // since we didn't build rustdoc json for all releases yet, // this redirect might redirect to a location that doesn't exist. Ok(super::axum_cached_redirect( @@ -3166,6 +3171,7 @@ mod test { #[test_case("0.1.0/json"; "rustdoc status false")] #[test_case("0.2.0/unknown-target/json"; "unknown target")] + #[test_case("0.2.0/json/99"; "target file doesnt exist")] #[test_case("0.42.0/json"; "unknown version")] fn json_download_not_found(request_path_suffix: &str) { async_wrapper(|env| async move {