fix: return IndexNotExist on remote drop index 404 (#2380)

Prior to this commit, attempting to drop an index that did not exist
would return a TableNotFound error stating that the target table does
not exist -- even when it did exist. Instead, we now return an
IndexNotFound error.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling when attempting to drop a non-existent index,
providing a more accurate error message.
- **Tests**
- Added a test to verify correct error reporting when dropping an index
that does not exist.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Wyatt Alt
2025-05-07 17:24:05 -07:00
committed by GitHub
parent 9ee152eb42
commit 75c257ebb6

View File

@@ -1325,7 +1325,12 @@ impl<S: HttpSend> BaseTable for RemoteTable<S> {
self.name, index_name
));
let (request_id, response) = self.send(request, true).await?;
self.check_table_response(&request_id, response).await?;
if response.status() == StatusCode::NOT_FOUND {
return Err(Error::IndexNotFound {
name: index_name.to_string(),
});
};
self.client.check_response(&request_id, response).await?;
Ok(())
}
@@ -2879,6 +2884,22 @@ mod tests {
table.drop_index("my_index").await.unwrap();
}
#[tokio::test]
async fn test_drop_index_not_exists() {
let table = Table::new_with_handler("my_table", |request| {
assert_eq!(request.method(), "POST");
assert_eq!(
request.url().path(),
"/v1/table/my_table/index/my_index/drop/"
);
http::Response::builder().status(404).body("{}").unwrap()
});
// Assert that the error is IndexNotFound
let e = table.drop_index("my_index").await.unwrap_err();
assert!(matches!(e, Error::IndexNotFound { .. }));
}
#[tokio::test]
async fn test_wait_for_index() {
let table = _make_table_with_indices(0);