As a software engineer and devtools product manager, I learned that most companies are not giving their devs the tools they need to do an excellent job. I set out to try something new.
You're getting back a string of json from the API and parsing it. let content = JSON.parse(response.body); This appears to work.
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);
This appears to work.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 docontent[0]
, you're getting back the first element of an empty array, which is, understandably,undefined
. Then you try to get.data
on theundefined
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.
Its saying response is not defined.