I have a JSON POST request that does not return JSON response on the first attempt. Error: getaddrinfo ENOTFOUND {{domainname}}
When the same request is posted multiple times (3 to 4 times), then it returns proper response.
I have checked the code provided in the community, but could not find a solution for this.
Hi @abhi1788 , welcome to the community, and thanks for your question.
I will presume that you are using {{domainname}} in the request URL. The ENOTFOUND error indicates that the system couldn’t do a DNS lookup, which sounds like Postman is sending that string as-is, and not finding your variable to replace the literal string with your intended server string.
Are you building this variable dynamically? Or is it an environment or collection variable? Can you give us a little more information?
Thanks @ianthepostmanaut to your response. {{domainname}} is an environment variable. It is quite strange that DNS is not resolving to string. But, this does not happen everytime. Out of 10 times, the request is processed correctly for 4 times.
Therefore, I want to keep it posting until I see the response.
Yes, this does seem strange. Can you give us a screenshot of the console showing how it’s not using the {{domainname}} variable, and using that literal string instead? Maybe a screenshot of how you’re using the variable in the request URL as well?
That’s certainly an interesting problem to have.
It would be ideal to get to the root of the problem and not have to do anything with retries like Ian is trying to help with.
But another possible solution to implement a version of retrying a request could be to use postman.setNextRequest(request.name) behind some kind of check with a counter to loop only a certain number of times until you get a response and postman.setNextRequest(null) after the 10th request for example.
Here’s a sample I was able to find that demonstrates this for you
I had the similar problem: after I installed a local Postman app, some of my requests stopped working, but they still worked in a web. Then I noticed that some of the slashes “/” have been removed in my URLs during the sync - they were simply missing in the local app:
local app: https:/{{cpihostname}}http/parallel_multicast
web app: https://{{cpihostname}}/http/parallel_multicast
After adding the back, it was all good.
Hope this helps someone…
Hi, did you solve the problem? It does not seem to have the solution here. I have the same problem. Some of the requests I need to run again for it to be successful.
On of the possibilities, which is not working for all my requests is to have the following function in the pre-request of the collection:
let sendRequestWithRetry = () => {
// Send the request
pm.sendRequest(pm.request, function (err, response) {
//console.log("... sending request ... ")
if (err) {
// console.log("sendRequestWithRetry")
const maxRetries = Number(pm.collectionVariables.get("timeoutRetryMax"));
let retryCount = Number(pm.collectionVariables.get("timeoutRetryCount"));
console.log(`maxRetries = ${maxRetries}, retryCount = ${retryCount}`)
if ((err.code === 'ETIMEDOUT' || err.code === "ESOCKETTIMEDOUT" || err.code === "ECONNREFUSED" || err.code === "ENOTFOUND") && retryCount < maxRetries) {
// Retry the request with a delay
console.log(`Retrying request (Attempt ${retryCount})...`);
retryCount++;
pm.collectionVariables.set("timeoutRetryCount", retryCount)
setTimeout(sendRequestWithRetry, 2000);
} else {
// Handle other errors if needed
// console.log('****** (retryCount >= maxRetries) go on withthe next request ********')
console.log('****** (retryCount >= maxRetries) Stop next tests executions ********')
console.error(err);
postman.setNextRequest(null)
}
} else {
// Request completed successfully
console.log(`Response received in ${response.responseTime} ms`);
console.log(`Request completed successfully (Attempt ${pm.collectionVariables.get("timeoutRetryCount")})...`);
}
});
}