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
CodePudding user response:
You just need to use timeout
option:
timeout
specifies the number of milliseconds before the request times out. If the request takes longer thantimeout
, the request will be aborted. timeout: 1000, // default is0
(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.