Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make if within 30 seconds

How to write an error to the console when I have not received an answer within 30 seconds?

const req = await axios.post(`http://316.132.61.31:2000`)
  .catch(err => console.log(err));

I need to understand how it works

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You just need to use timeout option:

timeout specifies the number of milliseconds before the request times out.
If the request takes longer than timeout, the request will be aborted.
timeout: 1000, // default is 0 (no timeout)

const req = await axios.post(`http://316.132.61.31:2000`, null, { timeout: 30000 }).catch(err => console.log(err));

See the official documentation here

P.S. Please read the documentation before asking your next question about axios and indicate what you tried and what options you used in the question.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading