mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
made error handling more concise
This commit is contained in:
+12
-36
@@ -151,26 +151,14 @@ pub(crate) async fn get_content_route(
|
|||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
||||||
| Ok(meta) => meta,
|
| Ok(meta) => meta,
|
||||||
| Err(e) => {
|
| Err(conduwuit::Error::Io(e)) => {
|
||||||
match e {
|
if matches!(e.kind(), std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::NotFound) {
|
||||||
| conduwuit::Error::Io(e) => {
|
return Err!(Request(NotFound("Media not found.")));
|
||||||
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."))),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Err!(Request(Unknown("Unknown error when fetching file.")));
|
||||||
},
|
},
|
||||||
|
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_content::v1::Response {
|
Ok(get_content::v1::Response {
|
||||||
@@ -209,26 +197,14 @@ pub(crate) async fn get_content_as_filename_route(
|
|||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
||||||
| Ok(meta) => meta,
|
| Ok(meta) => meta,
|
||||||
| Err(e) => {
|
| Err(conduwuit::Error::Io(e)) => {
|
||||||
match e {
|
if matches!(e.kind(), std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::NotFound) {
|
||||||
| conduwuit::Error::Io(e) => {
|
return Err!(Request(NotFound("Media not found.")));
|
||||||
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."))),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Err!(Request(Unknown("Unknown error when fetching file.")));
|
||||||
},
|
},
|
||||||
|
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_content_as_filename::v1::Response {
|
Ok(get_content_as_filename::v1::Response {
|
||||||
|
|||||||
Reference in New Issue
Block a user