My use case is that I want to make a request again, if the response is not received in 5 seconds. Below is my code, can you help me achieve that?
try {
const details = {
grant_type: "password",
client_id: config?.ClientId,
client_secret: config?.ClientSecret,
username: config?.Username,
password: config?.Password,
};
console.log('๐ ~ file: authenticate.js ~ line 17 ~ details', details);
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
const data = {
url: `${URL}`,
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
json: true,
data: formBody,
};
const response = await axios(data);
console.log('๐ ~ file: authenticate.js ~ line 35 ~ response', response);
return response.data;
}
catch (error) {
console.log("Error While authenticating", error);
return error
}