How to automate a request which doesn't give response on the first attempt. It throws Error: getaddrinfo ENOTFOUND {{domainname}}

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.

How to automate this scenario?

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?

Cheers,
Ian

Thanks @iandouglas 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. :thinking:

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 :smile:

1 Like