mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 00:55:00 +08:00
fix error 500 when sending bad rankingRules; fix #500
This commit is contained in:
parent
8aeddec982
commit
8df6d6e954
@ -115,7 +115,8 @@ pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
@ -177,7 +178,8 @@ pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
@ -229,7 +231,8 @@ pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
@ -284,7 +287,8 @@ pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
@ -342,7 +346,8 @@ pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
@ -395,7 +400,8 @@ pub async fn update_accept_new_fields(mut ctx: Request<Data>) -> SResult<Respons
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||
let update_id = index.settings_update(&mut writer, settings)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
|
@ -260,6 +260,11 @@ impl Server {
|
||||
self.post_request_async(&url, body);
|
||||
}
|
||||
|
||||
pub fn update_ranking_rules_sync(&mut self, body: Value) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
|
||||
self.post_request(&url, body)
|
||||
}
|
||||
|
||||
pub fn delete_ranking_rules(&mut self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
|
||||
self.delete_request_async(&url)
|
||||
|
@ -37,7 +37,7 @@ fn write_all_and_delete() {
|
||||
|
||||
let (response, _status_code) = server.get_ranking_rules();
|
||||
|
||||
let json = json!([
|
||||
let expected = json!([
|
||||
"typo",
|
||||
"words",
|
||||
"proximity",
|
||||
@ -46,7 +46,7 @@ fn write_all_and_delete() {
|
||||
"exactness"
|
||||
]);
|
||||
|
||||
assert_json_eq!(expect, response, ordered: false);
|
||||
assert_json_eq!(expected, response, ordered: false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -105,3 +105,37 @@ fn write_all_and_update() {
|
||||
|
||||
assert_json_eq!(expected, response, ordered: false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_undefined_rule() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
let body = json!([
|
||||
"typos",
|
||||
]);
|
||||
|
||||
let (_response, status_code) = server.update_ranking_rules_sync(body);
|
||||
assert_eq!(status_code, 400);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_malformed_custom_rule() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
let body = json!([
|
||||
"dsc(truc)",
|
||||
]);
|
||||
|
||||
let (_response, status_code) = server.update_ranking_rules_sync(body);
|
||||
assert_eq!(status_code, 400);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user