DEV Community

[Comment from a deleted post]
Collapse
 
dtuite profile image
David Tuite
  1. You're getting back a string of json from the API and parsing it. let content = JSON.parse(response.body); This appears to work.
  2. Next, you're looking up items on that JSON. e.g. content[0].data.children[0].data.permalink;

My guess is that the problem is that the content array in the JSON is sometimes empty. Then when you do content[0], you're getting back the first element of an empty array, which is, understandably, undefined. Then you try to get .data on the undefined and that triggers the error.

Try putting the JSON to the console and inspecting it visually to see if it has all the fields you expect.

let content = JSON.parse(response.body)
console.log(content)
Collapse
 
syn profile image
norman

Its saying response is not defined.