mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
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:
@@ -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)
|
||||
|
||||
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user