K
K
Kirill Shekhovtsov2019-02-13 17:56:09
JavaScript
Kirill Shekhovtsov, 2019-02-13 17:56:09

How to re-GET request in Node JS if request returned an error?

Good afternoon, I use the request-promise package in the project, but I would like an example on one of the popular packages (axios or others).
How can you intelligently make repeated get requests to the same URL with a delay of 10 seconds if the request returned an error from the site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Okhotnikov, 2019-02-13
@Ksedline

function get() {
axios.get('/user')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
    setTimeout(get, 10000)
  })
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question