From 27ff2d93632ec7c7eaca75288489fd7651ba6506 Mon Sep 17 00:00:00 2001 From: Ben Botwin Date: Sun, 15 Feb 2026 11:30:55 -0500 Subject: [PATCH] added more granular error handling for other file fetch function --- src/api/client/media.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/api/client/media.rs b/src/api/client/media.rs index 0d610011..528f2871 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -145,13 +145,32 @@ pub(crate) async fn get_content_route( media_id: &body.media_id, }; - let Ok(FileMeta { + let FileMeta { content, content_type, content_disposition, - }) = fetch_file(&services, &mxc, user, body.timeout_ms, None).await - else { - return Err!(Request(NotFound("Media not found."))); + } = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await { + | Ok(meta) => meta, + | Err(e) => { + match e { + | conduwuit::Error::Io(e) => { + match e.kind() { + | std::io::ErrorKind::PermissionDenied => + // to not leak that a file exists + { + return Err!(Request(NotFound("Media not found."))); + }, + | std::io::ErrorKind::NotFound => { + return Err!(Request(NotFound("Media not found."))); + }, + | _ => { + return Err!(Request(Unknown("Unknown error when fetching file."))); + }, + } + }, + | _ => return Err!(Request(Unknown("Unknown error when fetching file."))), + } + }, }; Ok(get_content::v1::Response {