convert object store error to wmill error for correct status code

This commit is contained in:
Diego Imbert
2025-08-07 17:44:18 +02:00
parent 878ac09775
commit f654e59ec9
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ pub async fn download_s3_file_internal(
pub async fn read_object_streamable(
s3_client: Arc<dyn ObjectStore>,
file_key: &str,
) -> anyhow::Result<Response> {
) -> error::Result<Response> {
Err(error::Error::internal_err(
"Not implemented in Windmill's Open Source repository".to_string(),
))
+39
View File
@@ -286,3 +286,42 @@ where
Self(err.into())
}
}
impl From<object_store::Error> for Error {
fn from(err: object_store::Error) -> Self {
use object_store::Error::*;
match err {
Generic { store, source } => Error::Generic(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Generic {} error: {}", store, source),
),
NotFound { path, source } => Error::NotFound(format!("{}: {}", path, source)),
InvalidPath { source } => Error::BadRequest(format!("Invalid path: {}", source)),
JoinError { source } => Error::InternalErr(format!("Join error: {}", source)),
NotSupported { source } => {
Error::BadRequest(format!("Operation not supported: {}", source))
}
AlreadyExists { path, source } => {
Error::BadRequest(format!("Object at {} already exists: {}", path, source))
}
Precondition { path, source } => {
Error::BadRequest(format!("Precondition failed at {}: {}", path, source))
}
NotModified { path, source } => {
Error::ExecutionErr(format!("Not modified at {}: {}", path, source))
}
NotImplemented => Error::BadRequest("Operation not yet implemented.".to_string()),
PermissionDenied { path, source } => {
Error::PermissionDenied(format!("Permission denied at {}: {}", path, source))
}
Unauthenticated { path, source } => {
Error::NotAuthorized(format!("Unauthenticated for {}: {}", path, source))
}
UnknownConfigurationKey { store, key } => Error::BadConfig(format!(
"Invalid config key '{}' for store '{}'",
key, store
)),
_ => Error::InternalErr(format!("Object store error: {}", err)),
}
}
}