Why are the 404 labelled channels not coming up with my API get?

Why are the 404 labelled channels not coming up with my API get?
0

#1

Here is my link to my project, and for some reason, the channels that the project labels as “nonexistent” are breaking the api call. As you can see I have a console.log(data) to let me see the output from my json get, and the channels dont even show up, but when I input the links to them in my browser, I at least get an error output. Why isnt the console log picking up on this, it’s affecting the part of the project where I have a special notation for “non existent” channels.


#2

The callback function you have for getJSON is actually just a success handler. This means that when the server responds with an error, that function won’t be invoked. I think the simplest solution here is to use the promise API to catch errors. Basically, it will look like this

$.getJSON(url)
    .then(function(data) { /* handle success here */ })
    .catch(function(error) { /* handle error here */ })

Notice that instead of including the function as a parameter to getJSON, we’re using the then and catch methods.


#3

Okay, that’s interesting thanks. That makes sense, someone told me the other day that json is just shorthand for ajax, and ajax has success and failure functions. I will try and implement this and see how that goes.