I want to execute a post request using reqwest
and retry it in case of error. To retry I am using again
crate. My code looks like this:
pub async fn post_part(&self, url: &str, headers: HeaderMap, body: Form) -> Result<Response, reqwest::Error> {
let response = self.retry_policy.retry( || {
self.client.request(Method::POST, url).headers(headers.clone()).multipart(body).send()
}).await?;
Ok(response)
}
Getting this error:
let response = self.retry_policy.retry( || {
----- ^^ this closure implements `FnOnce`, not `FnMut`
the requirement to implement `FnMut` derives from here
self.client.request(Method::POST, url).headers(headers.clone()).multipart(body).send() ---- closure is `FnOnce` because it moves the variable `body` out of its environment
self.retry_policy:
again::RetryPolicy::fixed(Duration::from_millis(1000))
.with_jitter(true).with_max_retries(5)
.with_max_delay(Duration::from_millis(2000));
Need help to overcome this issue.