N
N
Nikolay372019-01-27 16:56:31
JSON
Nikolay37, 2019-01-27 16:56:31

How to fix token error when requesting from JSON?

send()
function send() {
  console.log('начало send')
  request.get({
    url: 'https://google.com'
  }, function(err, res, body) {
    if (err) {
      console.log('ERROR', err);
      console.log('Вызвал send, ошибка')
      setTimeout(send, 10000)
    } else {
      let s = '111'
      let i = 0
      console.log('Запрос успешен')
      console.log(JSON.parse(body)['time'])
      setTimeout(send, 10000)
    }
  })
}

The first time the function is called, everything is fine, the console.log(JSON.parse(body)['time']) response is displayed in the console.
And on the second request, I no longer receive such a response, I have an error on this line Unexpected token < in json at position 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
McBernar, 2019-01-27
@Nikolay37

An error in the JSON parser itself. Not JSON arrives and immediately falls off with a critical error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question