Merge pull request #759 from MarinPostma/document-delete-error

return error on deleting unexisting index
This commit is contained in:
Clément Renault 2020-06-05 12:33:06 +02:00 committed by GitHub
commit cff9e1fd94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -311,9 +311,11 @@ async fn delete_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
data.db.delete_index(&path.index_uid)?;
Ok(HttpResponse::NoContent().finish())
if data.db.delete_index(&path.index_uid)? {
Ok(HttpResponse::NoContent().finish())
} else {
Err(Error::index_not_found(&path.index_uid).into())
}
}
#[derive(Deserialize)]

View File

@ -195,6 +195,12 @@ async fn rename_index() {
async fn delete_index_and_recreate_it() {
let mut server = common::Server::with_uid("movies");
// 0 - delete unexisting index is error
let (response, status_code) = server.delete_request("/indexes/test").await;
assert_eq!(status_code, 404);
assert_eq!(&response["errorCode"], "index_not_found");
// 1 - Create a new index
let body = json!({