fix: properly return errors for malformed config (#2027)
This commit is contained in:
@@ -185,7 +185,17 @@ pub async fn get_extensions(
|
||||
|
||||
match ExtensionManager::get_all() {
|
||||
Ok(extensions) => Ok(Json(ExtensionResponse { extensions })),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
Err(err) => {
|
||||
// Return UNPROCESSABLE_ENTITY only for DeserializeError, INTERNAL_SERVER_ERROR for everything else
|
||||
if err
|
||||
.downcast_ref::<goose::config::base::ConfigError>()
|
||||
.is_some_and(|e| matches!(e, goose::config::base::ConfigError::DeserializeError(_)))
|
||||
{
|
||||
Err(StatusCode::UNPROCESSABLE_ENTITY)
|
||||
} else {
|
||||
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +206,7 @@ pub async fn get_extensions(
|
||||
responses(
|
||||
(status = 200, description = "Extension added or updated successfully", body = String),
|
||||
(status = 400, description = "Invalid request"),
|
||||
(status = 422, description = "Could not serialize config.yaml"),
|
||||
(status = 500, description = "Internal server error")
|
||||
)
|
||||
)]
|
||||
|
||||
@@ -109,8 +109,7 @@ impl ExtensionManager {
|
||||
/// Get all extensions and their configurations
|
||||
pub fn get_all() -> Result<Vec<ExtensionEntry>> {
|
||||
let config = Config::global();
|
||||
let extensions: HashMap<String, ExtensionEntry> =
|
||||
config.get_param("extensions").unwrap_or_default();
|
||||
let extensions: HashMap<String, ExtensionEntry> = config.get_param("extensions")?;
|
||||
Ok(Vec::from_iter(extensions.values().cloned()))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
mod base;
|
||||
pub mod base;
|
||||
mod experiments;
|
||||
pub mod extensions;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user