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
|
### ❌ Breaking changes
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
### 🐛 Bug fix
|
### 🐛 Bug fix
|
||||||
|
|
||||||
|
- fix: search_extension should not panic when ext is not found #983
|
||||||
|
|
||||||
### ✈️ Improvements
|
### ✈️ Improvements
|
||||||
|
|
||||||
## 0.9.0 (2025-11-19)
|
## 0.9.0 (2025-11-19)
|
||||||
|
|||||||
@@ -104,15 +104,23 @@ pub(crate) async fn search_extension(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to send request: {:?}", e))?;
|
.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
|
// The response of a ES style search request
|
||||||
let mut response: JsonObject<String, Json> = response
|
let mut response: JsonObject<String, Json> = response
|
||||||
.json()
|
.json()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to parse response: {:?}", e))?;
|
.map_err(|e| format!("Failed to parse response: {:?}", e))?;
|
||||||
|
|
||||||
let hits_json = response
|
let hits_json = response.remove("hits").unwrap_or_else(|| {
|
||||||
.remove("hits")
|
panic!(
|
||||||
.expect("the JSON response should contain field [hits]");
|
"the JSON response should contain field [hits], response [{:?}]",
|
||||||
|
response
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let mut hits = match hits_json {
|
let mut hits = match hits_json {
|
||||||
Json::Object(obj) => obj,
|
Json::Object(obj) => obj,
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
|
|||||||
Reference in New Issue
Block a user