JSON.parse: unexpected end of data

jemand anders

Erfahrenes Mitglied
Hallo,

ich habe merkwürdiges Phänomen beim Fetchen von Posts, das eigentlich nicht auftreten sollte und auch nicht auftritt, wenn man die Sätze, die in der Gesamtabfrage einen Fehler liefern, einzeln abfragt.

Vielleicht hat jemand eine Idee, was es sein kann.

Gruß

Javascript:
(function() {
 
  console.clear()
 
  const urls = [
    "post-001.html",
    …,
    …,
    "post-148.html"
  ]

  const urlsSet = [...new Set(urls)]

  var errors = 0
  const postUrls = urlsSet.slice()
  //const postUrls = ['post-100.html']

  console.log(postUrls.length)

  const getPost = async (url, index) => {
    try {
      const res = await fetch(`/feeds/posts/default?alt=json&path=${url}`)
      const data = res.json() //await res.json() FEHLERQUELLE
      console.log(index, url)
    } catch (error) {
      errors++
      console.log('error : ', errors, url, error);
    }
  }

  const fetchPosts = () => {
    postUrls.forEach(
      //async (url, index) => await getPost(url, index)
      (url, index) => getPost(url, index)
    )
    console.log('ok')
  }

  fetchPosts()

})()

Der, der bei ca. 30 Prozent der Sätze erscheint:

Code:
Fetch error :  70 post-xxx.html SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
 
Zuletzt bearbeitet:
Zurück