Hi Friends,
Does Axios support keepalive
functionality same as the native fetch()
?
keepalive
The keepalive option can be used to allow the request to outlive the page. Fetch with the keepalive flag is a replacement for the Navigator.sendBeacon() API.
https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
I've found that Axios randomly send duplicate POST request to API, which cause the duplicate data in the system.
At first I thought that the user click the button several times, but today I saw that user just click the button only one time and the requests were sent 4 times. After that user try to clich that same button again, this time the request is sent one time correctly.
This is from our UAT system today, but we've found similar issues on production for 3-4 months and it just happen randomly.. Is there any solution for this issue?
createError.js:16 Uncaught (in promise) Error: Network Error
at createError (createError.js:16:1)
at XMLHttpRequest.handleError (xhr.js:99:1)
I'm using Axios request for 2 API's. For one of the API, I'm using below code to set certificates globally -
https.globalAgent.options.ca = [
fs.readFileSync('certs/1.pem'),
fs.readFileSync('certs/2.pem'),
fs.readFileSync('certs/3.pem')
];
When I tried, Axios request for 1st API worked.
But second request, which is a Service Now request, throws error - Error: unable to get local issuer certificate
I tried configuring certificate specifically for the request, but first request itself is throwing same error.
async function getAuthToken() {
return await axios.post('Some URL' + "/authentication/connect/api1",
'grant_type=password&username=' +appID+ '&password=' + 'appPwd',
{
httpsAgent: new https.Agent({
options: {
ca: [
fs.readFileSync('certs/1.pem'),
fs.readFileSync('certs/2.pem'),
fs.readFileSync('certs/3.pem')
],
rejectUnauthorized: false
}
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic d3MudXNlcjo='
}
})
}
How to call second API without any errors ?