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")
|
||||
)
|
||||
)]
|
||||
|
||||
Reference in New Issue
Block a user