Answer the question
In order to leave comments, you need to log in
How to make fetch js make multiple request attempts when getting an error?
Good evening.
Can you please tell me how to use fetch to make a second request request when an error is received.
I would like, of course, to try to reach the server three times, and after that return an error if this did not happen.
Is there some special syntax or just using IF?
Thank you.
Answer the question
In order to leave comments, you need to log in
The second parameter then is a function on error, pass a link to the fetch call function into it. Approximately so
const fetchData = () => {
fetch(url).then(
response = > {
// код при успешном ответе
}, fetchData)
}
fetchData()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question