fix: search_extension should not panic when ext is not found (#983)

This commit fixes a bug that the search_extension() function panics
when the "GET /store/_search" interface returns a 404 response.

```
GET /store/_search?query=<query string>
{"_id":"_search","result":"not_found"}
```

It also improves the panic message by including varaible "response" in it,
so that we can inspect the actual response.

```
let hits_json = response.remove("hits").unwrap_or_else(|| {
    panic!(
        "the JSON response should contain field [hits], response [{:?}]",
        response
    )
});
```
This commit is contained in:
SteveLauC
2025-11-19 10:10:59 +08:00
committed by GitHub
parent 459705af70
commit 533bfaf45b
2 changed files with 14 additions and 3 deletions

View File

@@ -11,6 +11,9 @@ Information about release notes of Coco App is provided here.
### ❌ Breaking changes
### 🚀 Features
### 🐛 Bug fix
- fix: search_extension should not panic when ext is not found #983
### ✈️ Improvements
## 0.9.0 (2025-11-19)

View File

@@ -104,15 +104,23 @@ pub(crate) async fn search_extension(
.await
.map_err(|e| format!("Failed to send request: {:?}", e))?;
if response.status() == StatusCode::NOT_FOUND {
return Ok(Vec::new());
}
// The response of a ES style search request
let mut response: JsonObject<String, Json> = response
.json()
.await
.map_err(|e| format!("Failed to parse response: {:?}", e))?;
let hits_json = response
.remove("hits")
.expect("the JSON response should contain field [hits]");
let hits_json = response.remove("hits").unwrap_or_else(|| {
panic!(
"the JSON response should contain field [hits], response [{:?}]",
response
)
});
let mut hits = match hits_json {
Json::Object(obj) => obj,
_ => panic!(