softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.9k stars 167 forks source link

FormData not work #277

Open DokiDoki1103 opened 5 months ago

DokiDoki1103 commented 5 months ago

If the first request of using form data fails, I need to retry, but the second retry will definitely get stuck and no new request will be sent. It is suspected that the stream has been read and cannot be reused

After trying again, it will get stuck and error timeouts will occur one after another

import axiosRetry from "axios-retry";
import axios from "axios";
import FormData from 'form-data'

const form = new FormData()
form.append('my_field', 'my_value');

const instance = axios.create({
    headers: form.getHeaders(),
    maxContentLength: Infinity,
});

axiosRetry(instance, {
    retries: 3, 
    retryCondition(error) {
        console.log("retrying")
        return true
    }
});

instance.post('http://example.com/submit-form', form)
    .then((response) => {
        console.log('Success:', response.data);
    })
    .catch((error) => {
        console.error('Error:', error);
    });
yutak23 commented 4 months ago

i think POST should not retry.

Also refer to https://github.com/softonic/axios-retry/issues/281.