fix: properly return errors for malformed config (#2027)

This commit is contained in:
Alex Hancock
2025-04-04 09:55:48 -04:00
committed by GitHub
parent e438b331fe
commit c3042067a0
6 changed files with 25 additions and 13 deletions
@@ -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")
)
)]