diff options
| author | soryu <soryu@soryu.co> | 2026-02-03 22:01:29 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-03 22:01:37 +0000 |
| commit | cf0a25af1d2834bfe6c5ea892ce5769936e5a673 (patch) | |
| tree | 476ba326ac1752281a441b5c17d2b3be4b23a2a9 /makima/src/daemon/api/client.rs | |
| parent | 8361916ce67f3d2ba191ebf27cb50e79cb42e39c (diff) | |
| download | soryu-cf0a25af1d2834bfe6c5ea892ce5769936e5a673.tar.gz soryu-cf0a25af1d2834bfe6c5ea892ce5769936e5a673.zip | |
Add makima chain mechanism
Diffstat (limited to 'makima/src/daemon/api/client.rs')
| -rw-r--r-- | makima/src/daemon/api/client.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/makima/src/daemon/api/client.rs b/makima/src/daemon/api/client.rs index 4ba4778..dbf3101 100644 --- a/makima/src/daemon/api/client.rs +++ b/makima/src/daemon/api/client.rs @@ -276,6 +276,48 @@ impl ApiClient { Err(last_error.unwrap()) } + /// Make a DELETE request with response and retry. + pub async fn delete_with_response<T: DeserializeOwned>(&self, path: &str) -> Result<T, ApiError> { + let url = format!("{}{}", self.base_url, path); + let mut last_error = None; + + for attempt in 0..MAX_RETRIES { + if attempt > 0 { + tokio::time::sleep(Self::backoff_delay(attempt - 1)).await; + } + + let result = self.client + .delete(&url) + .header("X-Makima-Tool-Key", &self.api_key) + .header("X-Makima-API-Key", &self.api_key) + .send() + .await; + + match result { + Ok(response) => { + match self.handle_response(response).await { + Ok(value) => return Ok(value), + Err(e) if Self::is_retryable(&e) && attempt < MAX_RETRIES - 1 => { + last_error = Some(e); + continue; + } + Err(e) => return Err(e), + } + } + Err(e) => { + let error = ApiError::Request(e); + if Self::is_retryable(&error) && attempt < MAX_RETRIES - 1 { + last_error = Some(error); + continue; + } + return Err(error); + } + } + } + + Err(last_error.unwrap()) + } + /// Handle API response. async fn handle_response<T: DeserializeOwned>( &self, |
