From 4db5ee5c44ab2b4269b297d786db4cd26faf95c0 Mon Sep 17 00:00:00 2001 From: rays Date: Fri, 9 Oct 2026 01:54:17 +0000 Subject: [PATCH] Answer a file id that does not exist with 404, not 500 (#162) POST /api/enclosures/{id}/download and DELETE /api/enclosures/{id} raised a missing row with anyhow!, which ApiError makes a 500 and logs as an api error. A page left open after a feed was forgotten asks for exactly that: the caller's mistake, a 404 like /media/{id} already answers, and as a 500 it turned up as a server error in the production check. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + src/web.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7f1e4..70ab118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Downloading or deleting a file the server no longer has answers "not found" instead of a server error. - A feed's page in the Directory, and subscribing from it, no longer wait while the whole Directory is put together to check that the one feed is in it. - The feed list, and each live update of it, no longer asks the database for a group's title once for every feed in the group. - An episode that came as a torrent of several files plays its largest file, and can be deleted, by hand or to free space, instead of staying on disk for good. diff --git a/src/web.rs b/src/web.rs index 94cbaf0..c7f5d7d 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1718,7 +1718,7 @@ async fn download_now( .ctx .db .enclosure(id).await? - .ok_or_else(|| anyhow::anyhow!("no enclosure {id}"))?; + .ok_or_else(|| ApiError::not_found(format!("no file {id}")))?; subscribed(&state, &user, &enc.feed_id).await?; if enc.path.is_some() { return Ok(StatusCode::NO_CONTENT); // Already here. @@ -1748,7 +1748,7 @@ async fn delete_file( .ctx .db .enclosure(id).await? - .ok_or_else(|| anyhow::anyhow!("no enclosure {id}"))?; + .ok_or_else(|| ApiError::not_found(format!("no file {id}")))?; subscribed(&state, &user, &enc.feed_id).await?; // There is one copy of the file: deleting it deletes everyone's. Say so before doing