Skip to content

Commit 6cae50f

Browse files
connortsui20ZENOTME
authored andcommitted
refactor: REST Catalog implementation (apache#965)
Followup of apache#962 apache#962 Introduced a bug where it is not some of the methods allow for both `StatusCode::OK` and `StatusCode::NO_CONTENT` as success cases, when in reality it should be one or the other (this was me, sorry about that). This PR attempts to unify the 3 different types of response helpers that essentially all do the exact same thing slightly differently. The main addition here is a function `query_catalog`: ```rust // Queries the Iceberg REST catalog with the given `Request` and a provided handler. pub async fn query_catalog<R, H, Fut>(&self, mut request: Request, handler: H) -> Result<R> where R: DeserializeOwned, H: FnOnce(Response) -> Fut, Fut: Future<Output = Result<R>>, { self.authenticate(&mut request).await?; let response = self.client.execute(request).await?; handler(response).await } ``` By allowing each `Catalog` method to specify how they want to handle the responses, it gets much finer control on the success/error cases as well as the error messages. Previously, there were 3 functions that all did similar things: ```rust pub async fn query<R: DeserializeOwned, E: DeserializeOwned + Into<Error>>( &self, mut request: Request, ) -> Result<R> { pub async fn execute<E: DeserializeOwned + Into<Error>>( &self, mut request: Request, ) -> Result<()> { pub async fn do_execute<R, E: DeserializeOwned + Into<Error>>( &self, mut request: Request, handler: impl FnOnce(&Response) -> Option<R>, ) -> Result<R> { ``` I'm also somewhat using this as a chance to refactor some other parts of this crate, mainly documentation and examples. @Xuanwo It would be great if I could get feedback on some of these proposed changes before I keep going!
1 parent 06d5321 commit 6cae50f

File tree

5 files changed

+404
-389
lines changed

5 files changed

+404
-389
lines changed

0 commit comments

Comments
 (0)